README.mdā¢5.98 kB
# Claude Desktop Integration Example
This example shows how to integrate your MCP server with Claude Desktop.
## Setup
### 1. Install Claude Desktop
Download and install Claude Desktop from [Anthropic's website](https://claude.ai/desktop).
### 2. Configure MCP Server
Claude Desktop reads its configuration from a JSON file. The location varies by operating system:
**Windows:**
```
%APPDATA%\Claude\claude_desktop_config.json
```
**macOS:**
```
~/Library/Application Support/Claude/claude_desktop_config.json
```
**Linux:**
```
~/.config/Claude/claude_desktop_config.json
```
### 3. Configuration File
Create or edit the configuration file with the following content:
```json
{
"mcpServers": {
"custom-mcp-server": {
"command": "node",
"args": ["C:\\path\\to\\your\\server.js"],
"cwd": "C:\\path\\to\\your\\project"
}
}
}
```
**Important:** Replace the paths with your actual project paths.
### 4. Start Your MCP Server
Before starting Claude Desktop, make sure your MCP server is ready:
```powershell
# Navigate to your project directory
cd C:\path\to\your\mcp-implementation
# Start the server (it will run in stdio mode for Claude)
node server.js
```
### 5. Start Claude Desktop
Launch Claude Desktop. It will automatically connect to your MCP server if configured correctly.
## Using MCP Tools in Claude
Once connected, you can ask Claude to use your MCP tools:
### Example Conversations
**File Operations:**
```
User: Can you read the contents of my README.md file?
Claude: I'll read the README.md file for you.
[Uses read_file tool]
```
**System Information:**
```
User: What system am I running on?
Claude: Let me check your system information.
[Uses get_system_info tool]
```
**Directory Listing:**
```
User: What files are in my current directory?
Claude: I'll list the files in your current directory.
[Uses list_directory tool]
```
**Web Scraping:**
```
User: Can you fetch the content from example.com?
Claude: I'll fetch the content from that URL for you.
[Uses fetch_url tool]
```
## Advanced Configuration
### Multiple MCP Servers
You can configure multiple MCP servers:
```json
{
"mcpServers": {
"filesystem-server": {
"command": "node",
"args": ["C:\\path\\to\\filesystem-server.js"]
},
"web-server": {
"command": "python",
"args": ["C:\\path\\to\\web-server.py"]
}
}
}
```
### Environment Variables
You can pass environment variables to your MCP server:
```json
{
"mcpServers": {
"custom-mcp-server": {
"command": "node",
"args": ["server.js"],
"cwd": "C:\\path\\to\\your\\project",
"env": {
"NODE_ENV": "production",
"API_KEY": "your-api-key",
"DEBUG": "mcp:*"
}
}
}
}
```
### Python Server Configuration
For Python servers:
```json
{
"mcpServers": {
"python-mcp-server": {
"command": "python",
"args": ["server.py"],
"cwd": "C:\\path\\to\\your\\project",
"env": {
"PYTHONPATH": "C:\\path\\to\\your\\project",
"LOG_LEVEL": "info"
}
}
}
}
```
## Troubleshooting
### Server Not Connecting
1. **Check file paths:** Ensure all paths in the config are correct and use double backslashes on Windows.
2. **Check server startup:** Test your server manually:
```powershell
node server.js
```
3. **Check Claude logs:** Look for error messages in Claude Desktop's developer console.
### Tools Not Working
1. **Verify tool registration:** Make sure your tools are properly registered in the server.
2. **Check permissions:** Some tools may require specific permissions (e.g., file access).
3. **Test tools individually:** Use a simple MCP client to test each tool.
### Performance Issues
1. **Optimize tool responses:** Keep tool responses concise and relevant.
2. **Use caching:** Implement caching for expensive operations.
3. **Limit concurrent operations:** Be mindful of resource usage.
## Security Considerations
### File Access
- Limit file operations to specific directories
- Validate file paths to prevent directory traversal
- Consider read-only access for sensitive areas
### Command Execution
- Disable command execution in production
- If needed, whitelist specific commands
- Always validate and sanitize inputs
### Network Access
- Restrict URL fetching to specific domains
- Implement timeouts for network requests
- Consider using a proxy for external requests
## Example Usage Session
```
User: Hi Claude! Can you help me explore my project directory?
Claude: I'd be happy to help you explore your project directory! Let me start by listing the contents of your current directory.
[Claude uses the list_directory tool]
I can see your project has several files and directories. Would you like me to:
1. Read the contents of any specific file?
2. Get information about your system?
3. Help you with any specific file operations?
User: Can you read my package.json file and tell me what dependencies I have?
Claude: I'll read your package.json file to see your project dependencies.
[Claude uses the read_file tool to read package.json]
Based on your package.json file, here are your dependencies:
**Production Dependencies:**
- @modelcontextprotocol/sdk: ^0.5.0
- express: ^4.18.2
- cors: ^2.8.5
- dotenv: ^16.3.1
- node-fetch: ^3.3.2
**Development Dependencies:**
- nodemon: ^3.0.2
- jest: ^29.7.0
- eslint: ^8.56.0
Your project appears to be an MCP (Model Context Protocol) server implementation using Express.js. Is there anything specific you'd like to know about these dependencies or any changes you'd like to make?
```
## Next Steps
1. Customize the MCP server for your specific use case
2. Add more tools and resources
3. Implement proper error handling and logging
4. Consider security implications for production use
5. Test thoroughly with various Claude interactions
For more advanced features and troubleshooting, see the main README.md file in the project root.