MCP Usage Documentation 
Overview 
MCP (Model Context Protocol) is an open standard that allows CodeBuddy to integrate with external tools and data sources. With MCP, you can extend the functionality of CodeBuddy by connecting it to various external services, databases, APIs, and more.
Core Concepts 
MCP Server 
An MCP server is an independent process that provides tools and resources, and CodeBuddy communicates with these servers via different transport protocols.
Transport Types 
STDIO: Communication with local processes via standard input/output
SSE: Communication with remote services via Server-Sent Events
HTTP: Communication with remote services via HTTP streaming
Configuration Scope 
user: Global user configuration, applied to all projects
project: Project-level configuration, applied to specific projects
local: Local configuration, applied only to the current session or workspace
For services with the same name (i.e., configurations with the same name in multiple scopes), the priority is as follows: local > project > user
Security Approval Mechanism 
MCP servers in the project scope require user approval upon first connection to ensure security. The system will display the server details, and the user can choose to approve or deny the connection.
Configuration Files 
Configuration File Locations 
user scope:
~/.codebuddy.jsonproject scope:
<project root directory>/.mcp.jsonlocal scope:
~/.codebuddy.json#/projects/<workspace_path>
Configuration File Format 
json
{
  "mcpServers": {
    "server-name": {
      "type": "stdio|sse|http",
      "command": "command path",
      "args": ["arg1", "arg2"],
      "env": {
        "ENV_VAR": "value"
      },
      "url": "http://example.com/mcp",
      "headers": {
        "Authorization": "Bearer token"
      },
      "description": "Server description"
    }
  },
  "//": "The projects field is only valid in the user scope file and identifies local scope configurations",
  "projects": {
    "/path/to/project": {
      "mcpServers": {
        "local-server": {
          "type": "stdio",
          "command": "./local-tool"
        }
      }
    }
  }
}Command Line Usage 
Add MCP Server 
STDIO Server 
bash
# Add a local executable
codebuddy mcp add --scope user my-tool -- /path/to/tool arg1 arg2
# Add a Python script
codebuddy mcp add --scope project python-tool -- python /path/to/script.pySSE Server 
bash
# Add an SSE server
codebuddy mcp add --scope user --transport sse sse-server https://example.com/mcp/sseHTTP Server 
bash
# Add an HTTP streaming server
codebuddy mcp add --scope project --transport http http-server https://example.com/mcp/httpAdd Server Using JSON Configuration 
bash
# Add via JSON string
codebuddy mcp add-json --scope user my-server '{"type":"stdio","command":"/usr/local/bin/tool","args":["--verbose"]}'Manage MCP Servers 
List All Servers 
bash
# List servers for all scopes
codebuddy mcp listView Server Details 
bash
# View specific server information
codebuddy mcp get my-serverRemove Server 
bash
# Remove a specific server
codebuddy mcp remove my-server
# Remove a server from a specific scope
codebuddy mcp remove my-server --scope userBest Practices 
1. Scope Selection 
Use user scope to store personal tools and global services
Use project scope to store project-specific tools
Use local scope to store temporary or experimental tools
2. Security Considerations 
Avoid storing sensitive information in configuration files
Use environment variables to pass authentication information
Regularly review and update server configurations
MCP servers in the project scope require user approval to connect, ensuring security
3. Performance Optimization 
Properly configure server timeouts
Avoid running too many STDIO servers simultaneously
Use caching mechanisms to reduce redundant connections
4. Error Handling 
Monitor server connection status
Implement reconnection mechanisms
Log and analyze error logs
Troubleshooting 
Common Issues 
Server Connection Failure 
Check if the command path is correct
Verify the parameters and environment variables
Confirm network connectivity (for remote servers)
Review the server logs
Tool Unavailable 
Confirm that the server has successfully connected
Check tool permission settings
Verify tool compatibility
Configuration Not Working 
Check configuration file syntax
Confirm scope priority
Restart the CodeBuddy application
Example Configuration 
Python Tool Server 
json
{
  "mcpServers": {
    "python-tools": {
      "type": "stdio",
      "command": "python",
      "args": ["-m", "my_mcp_server"],
      "env": {
        "PYTHONPATH": "/path/to/tools"
      },
      "description": "Python Toolset"
    }
  }
}Remote API Server 
json
{
  "mcpServers": {
    "api-server": {
      "type": "sse",
      "url": "https://api.example.com/mcp/sse",
      "headers": {
        "Authorization": "Bearer your-token",
        "X-API-Version": "v1"
       },
      "description": "Remote API Service"
    }
  }
}Node.js Local Server 
json
{
  "mcpServers": {
    "node-server": {
      "type": "stdio", 
      "command": "node",
      "args": ["./mcp-server.js"],
      "env": {
        "NODE_ENV": "production"
      },
      "description": "Node.js MCP Server"
    }
  }
}Extension Development 
Creating a Custom MCP Server 
Choose Implementation Language: Python, Node.js, Go, etc.
Implement MCP Protocol: Use the official SDK or implement it yourself
Define Tool Interfaces: Describe tool functionality and parameters
Handle Requests: Receive and process requests from CodeBuddy
Return Results: Return execution results in MCP format
SDKs and Libraries 
Python:
@ModelContextProtocol/python-sdkTypeScript/JavaScript:
@ModelContextProtocol/typescript-sdkOther Languages: Refer to official documentation for implementation