Skip to content

Commit 5fccdc4

Browse files
authored
feat: adds mcp functionality to fullstack app (#670)
* feat: adds mcp functionality to fullstack app Signed-off-by: Anthony D. Mays <[email protected]> * chore: refactors authenticateApiKey into shared util Signed-off-by: Anthony D. Mays <[email protected]> * chore: remove header logging Signed-off-by: Anthony D. Mays <[email protected]> * chore: updates claude desktop config example Signed-off-by: Anthony D. Mays <[email protected]> --------- Signed-off-by: Anthony D. Mays <[email protected]>
1 parent b9a5973 commit 5fccdc4

23 files changed

+2349
-2
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=Your Next Public Clerk Publishable Key here
22
CLERK_SECRET_KEY=Your Clerk Secret Key here
33
DB_TYPE=in-memory
4-
NEXT_PUBLIC_API_URL=http://localhost:3000
4+
NEXT_PUBLIC_API_URL=http://localhost:3000
5+
6+
# MCP Server Configuration
7+
MCP_API_KEY=your-secret-mcp-api-key-here
8+
MCP_DEFAULT_USER_ID=mcp-user
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Environment Configuration
2+
TODO_API_BASE_URL=http://localhost:3000/api/mcp
3+
MCP_API_KEY=your-secret-mcp-api-key-here
4+
5+
# Optional: Database connection for direct DB access
6+
DATABASE_URL=your_database_url_here
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Dependencies
2+
node_modules/
3+
npm-debug.log*
4+
5+
# Build output
6+
dist/
7+
*.tsbuildinfo
8+
9+
# Environment files
10+
.env
11+
.env.local
12+
.env.production
13+
14+
# IDE files
15+
.vscode/
16+
.idea/
17+
*.swp
18+
*.swo
19+
20+
# OS files
21+
.DS_Store
22+
Thumbs.db
23+
24+
# Logs
25+
logs/
26+
*.log
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Authentication Setup for Claude Desktop
2+
3+
## Quick Setup Guide
4+
5+
### 1. Configure Your Todo App
6+
7+
Add these environment variables to your todo app's `.env` file:
8+
9+
```bash
10+
# Add to /lib/javascript/fullstack_demo/.env
11+
MCP_API_KEY=your-secret-mcp-api-key-here
12+
MCP_DEFAULT_USER_ID=your-user-id-here
13+
```
14+
15+
**Generate a secure API key:**
16+
```bash
17+
# Generate a random API key
18+
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
19+
```
20+
21+
### 2. Configure MCP Server
22+
23+
Create/update the MCP server's `.env` file:
24+
25+
```bash
26+
# /lib/javascript/fullstack_demo/mcp-server/.env
27+
TODO_API_BASE_URL=http://localhost:3000/api/mcp
28+
MCP_API_KEY=your-secret-mcp-api-key-here
29+
```
30+
31+
**Use the same API key in both files!**
32+
33+
### 3. Configure Claude Desktop
34+
35+
Update your Claude Desktop config file:
36+
37+
**Location:** `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
38+
39+
```json
40+
{
41+
"mcpServers": {
42+
"todo-mcp-server": {
43+
"command": "node",
44+
"args": ["/full/path/to/your/mcp-server/dist/index.js"],
45+
"env": {
46+
"TODO_API_BASE_URL": "http://localhost:3000/api/mcp",
47+
"MCP_API_KEY": "your-secret-mcp-api-key-here"
48+
}
49+
}
50+
}
51+
}
52+
```
53+
54+
### 4. Build and Test
55+
56+
1. **Start your todo app:**
57+
```bash
58+
cd /lib/javascript/fullstack_demo
59+
npm run dev
60+
```
61+
62+
2. **Build the MCP server:**
63+
```bash
64+
cd /lib/javascript/fullstack_demo/mcp-server
65+
npm run build
66+
```
67+
68+
3. **Restart Claude Desktop** to pick up the new configuration
69+
70+
### 5. Test Authentication
71+
72+
In Claude Desktop, try:
73+
```
74+
Can you show me my todos?
75+
```
76+
77+
If authentication works, you should see your todos or an empty list.
78+
79+
## Troubleshooting
80+
81+
### "Unauthorized - Invalid API Key"
82+
- Check that the API key is the same in both `.env` files
83+
- Ensure the MCP server environment variables are set correctly
84+
- Restart Claude Desktop after config changes
85+
86+
### "Cannot connect to API"
87+
- Verify your todo app is running on the correct port
88+
- Check that the `TODO_API_BASE_URL` points to the MCP endpoints (`/api/mcp`)
89+
- Ensure firewalls aren't blocking the connection
90+
91+
### "User not found" errors
92+
- Set `MCP_DEFAULT_USER_ID` to a valid user ID from your system
93+
- For development, you can use any string like "test-user"
94+
95+
## Security Notes
96+
97+
⚠️ **Important for Production:**
98+
99+
1. **Keep API keys secret** - Never commit them to version control
100+
2. **Use environment variables** - Don't hardcode keys in your config
101+
3. **Rotate keys regularly** - Generate new API keys periodically
102+
4. **Limit scope** - Consider implementing user-specific API keys
103+
5. **Use HTTPS** - In production, always use HTTPS for API communication
104+
105+
## Alternative: User-Specific Authentication
106+
107+
For multiple users, you can extend the authentication to map API keys to specific users:
108+
109+
```typescript
110+
// In your API route
111+
const userKeyMap = {
112+
'api-key-1': 'user-1',
113+
'api-key-2': 'user-2',
114+
// etc.
115+
};
116+
117+
function authenticateApiKey(request: Request): string | null {
118+
const apiKey = request.headers.get('X-API-Key');
119+
return userKeyMap[apiKey] || null;
120+
}
121+
```
122+
123+
This allows each Claude Desktop user to have their own API key and access their own todos.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Todo MCP Server Deployment Guide
2+
3+
## Quick Start
4+
5+
1. **Build the server**:
6+
```bash
7+
cd mcp-server
8+
npm install
9+
npm run build
10+
```
11+
12+
2. **Configure environment**:
13+
```bash
14+
cp .env.example .env
15+
# Edit .env with your configuration
16+
```
17+
18+
3. **Test the server**:
19+
```bash
20+
node test.mjs
21+
```
22+
23+
## MCP Client Configuration
24+
25+
### Claude Desktop
26+
27+
Add this to your Claude Desktop configuration (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
28+
29+
```json
30+
{
31+
"mcpServers": {
32+
"todo-mcp-server": {
33+
"command": "node",
34+
"args": ["/path/to/your/mcp-server/dist/index.js"],
35+
"env": {
36+
"TODO_API_BASE_URL": "http://localhost:3000/api"
37+
}
38+
}
39+
}
40+
}
41+
```
42+
43+
### Other MCP Clients
44+
45+
For other MCP-compatible clients, use the stdio transport with:
46+
- **Command**: `node`
47+
- **Args**: `["/path/to/mcp-server/dist/index.js"]`
48+
- **Environment**: Set `TODO_API_BASE_URL` to your API base URL
49+
50+
## Environment Variables
51+
52+
| Variable | Description | Default | Required |
53+
| ------------------- | ----------------------------------- | --------------------------- | -------- |
54+
| `TODO_API_BASE_URL` | Base URL of the Todo API | `http://localhost:3000/api` | Yes |
55+
| `CLERK_SECRET_KEY` | Clerk secret key for authentication | - | Optional |
56+
57+
## Usage Examples
58+
59+
Once configured with an MCP client, you can use these tools:
60+
61+
### Get All Todos
62+
```
63+
Can you show me all my todos?
64+
```
65+
66+
### Create a Todo
67+
```
68+
Create a new todo: "Learn about MCP servers"
69+
```
70+
71+
### Update a Todo
72+
```
73+
Update todo ID 1 to mark it as completed
74+
```
75+
76+
### Get Statistics
77+
```
78+
Show me my todo statistics
79+
```
80+
81+
## Troubleshooting
82+
83+
### Common Issues
84+
85+
1. **Module not found errors**:
86+
- Ensure you've run `npm run build`
87+
- Check that the path in your MCP client config is correct
88+
89+
2. **API connection errors**:
90+
- Verify the Todo app is running on the correct port
91+
- Check the `TODO_API_BASE_URL` environment variable
92+
- Ensure the API endpoints are accessible
93+
94+
3. **Authentication errors**:
95+
- For production use, configure proper authentication
96+
- Set the `CLERK_SECRET_KEY` if using Clerk authentication
97+
98+
### Debug Mode
99+
100+
Run the server in development mode to see detailed logs:
101+
```bash
102+
npm run dev
103+
```
104+
105+
## Security Considerations
106+
107+
⚠️ **Important**: This MCP server is currently configured for development use. For production deployment:
108+
109+
1. **Authentication**: Implement proper API authentication
110+
2. **HTTPS**: Use HTTPS for API communication
111+
3. **Rate Limiting**: Implement rate limiting to prevent abuse
112+
4. **Input Validation**: Add additional input validation and sanitization
113+
5. **Error Handling**: Avoid exposing sensitive information in error messages
114+
115+
## API Compatibility
116+
117+
This MCP server is designed to work with the Todo app's REST API:
118+
119+
- `GET /api/todos` - Get all todos
120+
- `POST /api/todos` - Create a new todo
121+
- `PATCH /api/todos/{id}` - Update a todo
122+
- `DELETE /api/todos/{id}` - Delete a todo
123+
124+
Ensure your Todo app implements these endpoints for full compatibility.

0 commit comments

Comments
 (0)