MCP Tools
MCP (Model Context Protocol) is ByteBuddy's extension mechanism that allows connecting to external MCP servers to obtain additional tools, resources, and prompt functionality.
How MCP Works
In ByteBuddy, MCP works through the following methods:
- Connect External Servers: Connect to MCP servers via stdio, HTTP, or WebSocket
- Discover Available Features: Automatically discover tools, resources, and prompts provided by servers
- AI Assistant Invocation: AI assistants can call these MCP features during conversations
- Permission Control: Each connection is independently configured to ensure secure usage
Configuration File Location
MCP server configuration is located in your ByteBuddy configuration file:
# config.yaml
name: My ByteBuddy Config
version: 0.0.1
schema: v1
mcpServers:
# MCP server configuration goes hereConnection Types
ByteBuddy supports multiple MCP server connection methods:
1. STDIO Connection (Recommended for Local Tools)
mcpServers:
- name: browser-automation
command: npx
args:
- "@playwright/mcp@latest"
env:
NODE_ENV: production2. HTTP/SSE Connection
mcpServers:
- name: remote-api-server
url: https://api.example.com/mcp
type: sse
apiKey: ${API_KEY}
requestOptions:
timeout: 30000
headers:
User-Agent: ByteBuddy/1.03. WebSocket Connection
mcpServers:
- name: realtime-service
url: wss://service.example.com/ws
type: websocket
apiKey: ${WEBSOCKET_KEY}Common MCP Server Examples
1. Browser Automation Tools
mcpServers:
- name: browser-search
command: npx
args:
- "@playwright/mcp@latest"2. File System Enhancement
mcpServers:
- name: filesystem-tools
command: node
args:
- "./mcp-servers/filesystem-server.js"
cwd: ${PROJECT_ROOT}3. Database Connection
mcpServers:
- name: database-tools
command: python
args:
- "-m"
- "mcp_database_server"
env:
DB_URL: postgresql://user:pass@localhost/mydbHow to Use in Conversations
Once configured, MCP server features are automatically available in conversations:
Example Conversation 1: Using Browser Tools
User:
Help me open Baidu homepage and take a screenshot
AI Assistant (automatically calls MCP tools):
- Launch browser and visit Baidu homepage
- Take page screenshot
- Save to specified location
Example Conversation 2: Using Database Tools
User:
Query how many active users are in the user table
AI Assistant (automatically calls MCP database tools):
- Connect to database
- Execute query:
SELECT COUNT(*) FROM users WHERE status = 'active' - Return result: Currently 523 active users
Security Configuration
1. Environment Variable Management
mcpServers:
- name: secure-api
url: https://api.example.com/mcp
type: sse
apiKey: ${API_SECRET_KEY} # Read from environment variable
env:
DEBUG: false2. Connection Timeout Configuration
mcpServers:
- name: timeout-example
url: https://slow-api.example.com/mcp
type: sse
connectionTimeout: 60000 # 60-second connection timeout
requestOptions:
timeout: 120000 # 120-second request timeout3. Working Directory Restrictions
mcpServers:
- name: local-file-tools
command: node
args:
- "./tools/file-server.js"
cwd: /safe/workspace # Restrict working directory
env:
ALLOWED_PATHS: /safe/workspaceCustom MCP Servers
1. Create Node.js MCP Server
// custom-mcp-server.js
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server(
{
name: "custom-tools",
version: "1.0.0",
},
{
capabilities: {
tools: {},
},
},
);
// Define tools
server.setRequestHandler("tools/list", async () => ({
tools: [
{
name: "get_weather",
description: "Get weather information for specified city",
inputSchema: {
type: "object",
properties: {
city: {
type: "string",
description: "City name",
},
},
required: ["city"],
},
},
],
}));
// Handle tool calls
server.setRequestHandler("tools/call", async (request) => {
if (request.params.name === "get_weather") {
const { city } = request.params.arguments;
// Implement weather API call logic here
return {
content: [
{
type: "text",
text: `Current weather in ${city}: 22°C, sunny`,
},
],
};
}
});
// Start server
const transport = new StdioServerTransport();
await server.connect(transport);2. Create Python MCP Server
# custom_mcp_server.py
import asyncio
from mcp.server import Server
from mcp.server.stdio import stdio_server
app = Server("custom-python-server")
@app.list_tools()
async def handle_list_tools():
return [
{
"name": "calculate",
"description": "Perform mathematical calculations",
"inputSchema": {
"type": "object",
"properties": {
"expression": {
"type": "string",
"description": "Mathematical expression to calculate",
},
},
"required": ["expression"],
},
}
]
@app.call_tool()
async def handle_call_tool(name: str, arguments: dict):
if name == "calculate":
expression = arguments["expression"]
try:
result = eval(expression) # Note: Use safe evaluation in production
return {
"content": [
{
"type": "text",
"text": f"Result: {result}",
}
]
}
except Exception as e:
return {
"content": [
{
"type": "text",
"text": f"Error: {str(e)}",
}
]
}
async def main():
async with stdio_server() as (read_stream, write_stream):
await app.run(read_stream, write_stream)
if __name__ == "__main__":
asyncio.run(main())Advanced Configuration
1. Multiple Server Instances
mcpServers:
- name: browser-automation
command: npx
args:
- "@playwright/mcp@latest"
env:
BROWSER: chrome
- name: filesystem-operations
command: node
args:
- "./tools/filesystem-mcp.js"
cwd: ${PROJECT_ROOT}
- name: remote-api-gateway
url: https://api.gateway.com/mcp
type: sse
apiKey: ${GATEWAY_API_KEY}2. Conditional Server Loading
mcpServers:
- name: development-tools
command: node
args:
- "./tools/dev-server.js"
env:
NODE_ENV: development
# Only enable in development environment
disabled: ${ENVIRONMENT} === "production"3. Server Health Checks
mcpServers:
- name: critical-service
url: https://critical.service.com/mcp
type: sse
apiKey: ${CRITICAL_API_KEY}
healthCheck:
enabled: true
interval: 30000 # Check every 30 seconds
timeout: 5000 # 5-second timeout
endpoint: /healthBest Practices
1. Security Considerations
- Use environment variables for sensitive information
- Restrict working directory for file system access
- Implement proper authentication and authorization
- Regularly update MCP server packages
2. Performance Optimization
- Set appropriate timeouts for network connections
- Use connection pooling for frequently accessed services
- Monitor server resource usage
- Cache frequently used data when appropriate
3. Error Handling
- Implement graceful error recovery
- Provide meaningful error messages
- Log errors for debugging purposes
- Set up monitoring and alerting
Troubleshooting
Common Issues
Connection Failed
- Check if the MCP server is running
- Verify connection parameters (URL, API key, etc.)
- Check network connectivity
- Review server logs for error messages
Tools Not Available
- Ensure the server implements the tools/list handler
- Check if tools are properly registered
- Verify server capabilities configuration
- Restart ByteBuddy after configuration changes
Performance Issues
- Check server resource usage
- Optimize network requests
- Consider caching strategies
- Review timeout configurations
Debug Mode
Enable debug mode for troubleshooting:
mcpServers:
- name: debug-server
command: node
args:
- "./tools/debug-server.js"
- "--debug"
- "--log-level=verbose"
env:
DEBUG: mcp:*Resources
Through proper MCP configuration, you can significantly extend ByteBuddy's capabilities and integrate various external services to create a more powerful AI assistant.