gencode-ai 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +11 -0
- package/CLAUDE.md +70 -0
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/dist/agent/agent.d.ts +84 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +233 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/index.d.ts +6 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +6 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/types.d.ts +47 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +5 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/cli/components/App.d.ts +14 -0
- package/dist/cli/components/App.d.ts.map +1 -0
- package/dist/cli/components/App.js +395 -0
- package/dist/cli/components/App.js.map +1 -0
- package/dist/cli/components/CommandSuggestions.d.ts +13 -0
- package/dist/cli/components/CommandSuggestions.d.ts.map +1 -0
- package/dist/cli/components/CommandSuggestions.js +32 -0
- package/dist/cli/components/CommandSuggestions.js.map +1 -0
- package/dist/cli/components/Header.d.ts +9 -0
- package/dist/cli/components/Header.d.ts.map +1 -0
- package/dist/cli/components/Header.js +13 -0
- package/dist/cli/components/Header.js.map +1 -0
- package/dist/cli/components/Input.d.ts +13 -0
- package/dist/cli/components/Input.d.ts.map +1 -0
- package/dist/cli/components/Input.js +27 -0
- package/dist/cli/components/Input.js.map +1 -0
- package/dist/cli/components/Logo.d.ts +2 -0
- package/dist/cli/components/Logo.d.ts.map +1 -0
- package/dist/cli/components/Logo.js +8 -0
- package/dist/cli/components/Logo.js.map +1 -0
- package/dist/cli/components/Messages.d.ts +37 -0
- package/dist/cli/components/Messages.d.ts.map +1 -0
- package/dist/cli/components/Messages.js +106 -0
- package/dist/cli/components/Messages.js.map +1 -0
- package/dist/cli/components/ModelSelector.d.ts +13 -0
- package/dist/cli/components/ModelSelector.d.ts.map +1 -0
- package/dist/cli/components/ModelSelector.js +72 -0
- package/dist/cli/components/ModelSelector.js.map +1 -0
- package/dist/cli/components/Spinner.d.ts +12 -0
- package/dist/cli/components/Spinner.d.ts.map +1 -0
- package/dist/cli/components/Spinner.js +45 -0
- package/dist/cli/components/Spinner.js.map +1 -0
- package/dist/cli/components/index.d.ts +12 -0
- package/dist/cli/components/index.d.ts.map +1 -0
- package/dist/cli/components/index.js +12 -0
- package/dist/cli/components/index.js.map +1 -0
- package/dist/cli/components/theme.d.ts +31 -0
- package/dist/cli/components/theme.d.ts.map +1 -0
- package/dist/cli/components/theme.js +36 -0
- package/dist/cli/components/theme.js.map +1 -0
- package/dist/cli/index-legacy.d.ts +7 -0
- package/dist/cli/index-legacy.d.ts.map +1 -0
- package/dist/cli/index-legacy.js +431 -0
- package/dist/cli/index-legacy.js.map +1 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +116 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/ink-cli.d.ts +7 -0
- package/dist/cli/ink-cli.d.ts.map +1 -0
- package/dist/cli/ink-cli.js +105 -0
- package/dist/cli/ink-cli.js.map +1 -0
- package/dist/cli/session-picker.d.ts +16 -0
- package/dist/cli/session-picker.d.ts.map +1 -0
- package/dist/cli/session-picker.js +280 -0
- package/dist/cli/session-picker.js.map +1 -0
- package/dist/cli/ui.d.ts +61 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/ui.js +364 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +6 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/manager.d.ts +31 -0
- package/dist/config/manager.d.ts.map +1 -0
- package/dist/config/manager.js +65 -0
- package/dist/config/manager.js.map +1 -0
- package/dist/config/types.d.ts +22 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +6 -0
- package/dist/config/types.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/index.d.ts +10 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +9 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/init.d.ts +20 -0
- package/dist/memory/init.d.ts.map +1 -0
- package/dist/memory/init.js +332 -0
- package/dist/memory/init.js.map +1 -0
- package/dist/memory/manager.d.ts +85 -0
- package/dist/memory/manager.d.ts.map +1 -0
- package/dist/memory/manager.js +234 -0
- package/dist/memory/manager.js.map +1 -0
- package/dist/memory/types.d.ts +74 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +6 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/permissions/index.d.ts +7 -0
- package/dist/permissions/index.d.ts.map +1 -0
- package/dist/permissions/index.js +6 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/permissions/manager.d.ts +32 -0
- package/dist/permissions/manager.d.ts.map +1 -0
- package/dist/permissions/manager.js +79 -0
- package/dist/permissions/manager.js.map +1 -0
- package/dist/permissions/types.d.ts +14 -0
- package/dist/permissions/types.d.ts.map +1 -0
- package/dist/permissions/types.js +17 -0
- package/dist/permissions/types.js.map +1 -0
- package/dist/providers/anthropic.d.ts +20 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +185 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/gemini.d.ts +21 -0
- package/dist/providers/gemini.d.ts.map +1 -0
- package/dist/providers/gemini.js +241 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/index.d.ts +34 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +72 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/openai.d.ts +19 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +221 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/types.d.ts +125 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +6 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/session/index.d.ts +6 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +6 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +101 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +295 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/session/types.d.ts +39 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +10 -0
- package/dist/session/types.js.map +1 -0
- package/dist/tools/builtin/bash.d.ts +7 -0
- package/dist/tools/builtin/bash.d.ts.map +1 -0
- package/dist/tools/builtin/bash.js +80 -0
- package/dist/tools/builtin/bash.js.map +1 -0
- package/dist/tools/builtin/edit.d.ts +7 -0
- package/dist/tools/builtin/edit.d.ts.map +1 -0
- package/dist/tools/builtin/edit.js +32 -0
- package/dist/tools/builtin/edit.js.map +1 -0
- package/dist/tools/builtin/glob.d.ts +7 -0
- package/dist/tools/builtin/glob.d.ts.map +1 -0
- package/dist/tools/builtin/glob.js +36 -0
- package/dist/tools/builtin/glob.js.map +1 -0
- package/dist/tools/builtin/grep.d.ts +7 -0
- package/dist/tools/builtin/grep.d.ts.map +1 -0
- package/dist/tools/builtin/grep.js +59 -0
- package/dist/tools/builtin/grep.js.map +1 -0
- package/dist/tools/builtin/read.d.ts +7 -0
- package/dist/tools/builtin/read.d.ts.map +1 -0
- package/dist/tools/builtin/read.js +29 -0
- package/dist/tools/builtin/read.js.map +1 -0
- package/dist/tools/builtin/write.d.ts +7 -0
- package/dist/tools/builtin/write.d.ts.map +1 -0
- package/dist/tools/builtin/write.js +24 -0
- package/dist/tools/builtin/write.js.map +1 -0
- package/dist/tools/index.d.ts +38 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +32 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +22 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +71 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/types.d.ts +62 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +126 -0
- package/dist/tools/types.js.map +1 -0
- package/docs/README.md +16 -0
- package/docs/proposals/0001-web-fetch-tool.md +293 -0
- package/docs/proposals/0002-web-search-tool.md +306 -0
- package/docs/proposals/0003-task-subagents.md +333 -0
- package/docs/proposals/0004-plan-mode.md +338 -0
- package/docs/proposals/0005-todo-system.md +299 -0
- package/docs/proposals/0006-memory-system.md +539 -0
- package/docs/proposals/0007-context-management.md +429 -0
- package/docs/proposals/0008-checkpointing.md +327 -0
- package/docs/proposals/0009-hooks-system.md +343 -0
- package/docs/proposals/0010-mcp-integration.md +382 -0
- package/docs/proposals/0011-custom-commands.md +374 -0
- package/docs/proposals/0012-ask-user-question.md +317 -0
- package/docs/proposals/0013-multi-edit-tool.md +345 -0
- package/docs/proposals/0014-lsp-tool.md +478 -0
- package/docs/proposals/0015-ls-tool.md +407 -0
- package/docs/proposals/0016-kill-shell-tool.md +455 -0
- package/docs/proposals/0017-background-tasks.md +489 -0
- package/docs/proposals/0018-parallel-tool-execution.md +415 -0
- package/docs/proposals/0019-session-enhancements.md +462 -0
- package/docs/proposals/0020-session-summarization.md +447 -0
- package/docs/proposals/0021-skills-system.md +409 -0
- package/docs/proposals/0022-plugin-system.md +467 -0
- package/docs/proposals/0023-permission-enhancements.md +470 -0
- package/docs/proposals/0024-keyboard-shortcuts.md +443 -0
- package/docs/proposals/0025-cost-tracking.md +447 -0
- package/docs/proposals/0026-git-integration.md +475 -0
- package/docs/proposals/0027-enhanced-read-tool.md +514 -0
- package/docs/proposals/0028-enhanced-bash-tool.md +511 -0
- package/docs/proposals/0029-notebook-edit-tool.md +413 -0
- package/docs/proposals/0030-plugin-marketplace.md +360 -0
- package/docs/proposals/0031-command-suggestions.md +295 -0
- package/docs/proposals/0032-ide-integrations.md +328 -0
- package/docs/proposals/0033-enterprise-deployment.md +221 -0
- package/docs/proposals/0034-sandboxing.md +273 -0
- package/docs/proposals/0035-auto-updater.md +311 -0
- package/docs/proposals/0036-enhanced-glob-tool.md +267 -0
- package/docs/proposals/0037-enhanced-grep-tool.md +360 -0
- package/docs/proposals/0038-interactive-cli-ui.md +373 -0
- package/docs/proposals/0039-streaming-enhancements.md +359 -0
- package/docs/proposals/0040-multi-provider-enhancements.md +369 -0
- package/docs/proposals/README.md +84 -0
- package/docs/proposals/TEMPLATE.md +57 -0
- package/docs/proposals/research/claude-code-research.md +307 -0
- package/examples/agent-demo.ts +115 -0
- package/examples/basic.ts +166 -0
- package/package.json +50 -0
- package/src/agent/agent.ts +276 -0
- package/src/agent/index.ts +6 -0
- package/src/agent/types.ts +62 -0
- package/src/cli/components/App.tsx +565 -0
- package/src/cli/components/CommandSuggestions.tsx +58 -0
- package/src/cli/components/Header.tsx +36 -0
- package/src/cli/components/Input.tsx +60 -0
- package/src/cli/components/Logo.tsx +16 -0
- package/src/cli/components/Messages.tsx +210 -0
- package/src/cli/components/ModelSelector.tsx +135 -0
- package/src/cli/components/Spinner.tsx +72 -0
- package/src/cli/components/index.ts +21 -0
- package/src/cli/components/theme.ts +36 -0
- package/src/cli/index.tsx +136 -0
- package/src/config/index.ts +7 -0
- package/src/config/manager.ts +77 -0
- package/src/config/types.ts +25 -0
- package/src/index.ts +86 -0
- package/src/permissions/index.ts +7 -0
- package/src/permissions/manager.ts +97 -0
- package/src/permissions/types.ts +29 -0
- package/src/providers/anthropic.ts +224 -0
- package/src/providers/gemini.ts +295 -0
- package/src/providers/index.ts +97 -0
- package/src/providers/openai.ts +261 -0
- package/src/providers/types.ts +181 -0
- package/src/session/index.ts +6 -0
- package/src/session/manager.ts +354 -0
- package/src/session/types.ts +49 -0
- package/src/tools/builtin/bash.ts +92 -0
- package/src/tools/builtin/edit.ts +37 -0
- package/src/tools/builtin/glob.ts +42 -0
- package/src/tools/builtin/grep.ts +67 -0
- package/src/tools/builtin/read.ts +34 -0
- package/src/tools/builtin/write.ts +27 -0
- package/src/tools/index.ts +36 -0
- package/src/tools/registry.ts +83 -0
- package/src/tools/types.ts +172 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
# Proposal: MCP Integration (Model Context Protocol)
|
|
2
|
+
|
|
3
|
+
- **Proposal ID**: 0010
|
|
4
|
+
- **Author**: mycode team
|
|
5
|
+
- **Status**: Draft
|
|
6
|
+
- **Created**: 2025-01-15
|
|
7
|
+
- **Updated**: 2025-01-15
|
|
8
|
+
|
|
9
|
+
## Summary
|
|
10
|
+
|
|
11
|
+
Implement support for the Model Context Protocol (MCP), enabling mycode to connect to external tools and data sources through a standardized protocol. MCP servers can provide additional tools, resources, and prompts that extend the agent's capabilities.
|
|
12
|
+
|
|
13
|
+
## Motivation
|
|
14
|
+
|
|
15
|
+
Currently, mycode has a fixed set of built-in tools. This limits:
|
|
16
|
+
|
|
17
|
+
1. **Integrations**: Can't connect to external services (Jira, GitHub, Slack)
|
|
18
|
+
2. **Custom tools**: Can't add domain-specific tools
|
|
19
|
+
3. **Data access**: Can't access databases, APIs, or file systems beyond local
|
|
20
|
+
4. **Extensibility**: Adding new capabilities requires code changes
|
|
21
|
+
5. **Ecosystem**: Can't benefit from community-built tools
|
|
22
|
+
|
|
23
|
+
MCP provides a standard way to extend the agent with external capabilities.
|
|
24
|
+
|
|
25
|
+
## Claude Code Reference
|
|
26
|
+
|
|
27
|
+
Claude Code supports MCP as both client and server:
|
|
28
|
+
|
|
29
|
+
### Installation
|
|
30
|
+
```bash
|
|
31
|
+
claude mcp add filesystem # Add built-in server
|
|
32
|
+
claude mcp add github --env GITHUB_TOKEN=xxx # With config
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Configuration
|
|
36
|
+
```json
|
|
37
|
+
// .mcp.json (project-level)
|
|
38
|
+
{
|
|
39
|
+
"servers": {
|
|
40
|
+
"filesystem": {
|
|
41
|
+
"command": "npx",
|
|
42
|
+
"args": ["-y", "@anthropic/mcp-server-filesystem", "/path/to/dir"]
|
|
43
|
+
},
|
|
44
|
+
"github": {
|
|
45
|
+
"command": "npx",
|
|
46
|
+
"args": ["-y", "@anthropic/mcp-server-github"],
|
|
47
|
+
"env": {
|
|
48
|
+
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### MCP Capabilities
|
|
56
|
+
1. **Tools**: Additional tools the agent can use
|
|
57
|
+
2. **Resources**: Data sources (files, databases, APIs)
|
|
58
|
+
3. **Prompts**: Predefined prompt templates
|
|
59
|
+
|
|
60
|
+
### Tool Invocation
|
|
61
|
+
MCP tools appear as regular tools with prefix:
|
|
62
|
+
```
|
|
63
|
+
/mcp__github__create_issue title="Bug fix" body="..."
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Example Workflow
|
|
67
|
+
```
|
|
68
|
+
User: Create a Jira ticket for this bug
|
|
69
|
+
|
|
70
|
+
Agent: I'll use the Jira MCP server to create a ticket.
|
|
71
|
+
[mcp__jira__create_issue:
|
|
72
|
+
project: "MYPROJ"
|
|
73
|
+
summary: "Fix login validation"
|
|
74
|
+
description: "..."
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
Created issue MYPROJ-123: https://jira.example.com/browse/MYPROJ-123
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Detailed Design
|
|
81
|
+
|
|
82
|
+
### API Design
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
// src/mcp/types.ts
|
|
86
|
+
interface MCPServerConfig {
|
|
87
|
+
command: string;
|
|
88
|
+
args?: string[];
|
|
89
|
+
env?: Record<string, string>;
|
|
90
|
+
cwd?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface MCPTool {
|
|
94
|
+
name: string;
|
|
95
|
+
description: string;
|
|
96
|
+
inputSchema: JSONSchema;
|
|
97
|
+
serverName: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface MCPResource {
|
|
101
|
+
uri: string;
|
|
102
|
+
name: string;
|
|
103
|
+
mimeType?: string;
|
|
104
|
+
description?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface MCPPrompt {
|
|
108
|
+
name: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
arguments?: Array<{
|
|
111
|
+
name: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
required?: boolean;
|
|
114
|
+
}>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface MCPServer {
|
|
118
|
+
name: string;
|
|
119
|
+
config: MCPServerConfig;
|
|
120
|
+
tools: MCPTool[];
|
|
121
|
+
resources: MCPResource[];
|
|
122
|
+
prompts: MCPPrompt[];
|
|
123
|
+
status: 'connected' | 'disconnected' | 'error';
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// src/mcp/mcp-manager.ts
|
|
129
|
+
class MCPManager {
|
|
130
|
+
private servers: Map<string, MCPServer>;
|
|
131
|
+
|
|
132
|
+
constructor();
|
|
133
|
+
|
|
134
|
+
// Load servers from config files
|
|
135
|
+
async loadConfig(configPath: string): Promise<void>;
|
|
136
|
+
|
|
137
|
+
// Start an MCP server
|
|
138
|
+
async startServer(name: string, config: MCPServerConfig): Promise<MCPServer>;
|
|
139
|
+
|
|
140
|
+
// Stop a server
|
|
141
|
+
async stopServer(name: string): Promise<void>;
|
|
142
|
+
|
|
143
|
+
// Get all available tools from all servers
|
|
144
|
+
getTools(): MCPTool[];
|
|
145
|
+
|
|
146
|
+
// Execute an MCP tool
|
|
147
|
+
async executeTool(serverName: string, toolName: string, input: any): Promise<any>;
|
|
148
|
+
|
|
149
|
+
// Read a resource
|
|
150
|
+
async readResource(uri: string): Promise<any>;
|
|
151
|
+
|
|
152
|
+
// Get prompts
|
|
153
|
+
getPrompts(): MCPPrompt[];
|
|
154
|
+
|
|
155
|
+
// List connected servers
|
|
156
|
+
listServers(): MCPServer[];
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### MCP Protocol Implementation
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// src/mcp/protocol.ts
|
|
164
|
+
interface MCPMessage {
|
|
165
|
+
jsonrpc: '2.0';
|
|
166
|
+
id?: string | number;
|
|
167
|
+
method?: string;
|
|
168
|
+
params?: any;
|
|
169
|
+
result?: any;
|
|
170
|
+
error?: { code: number; message: string; data?: any };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
class MCPConnection {
|
|
174
|
+
private process: ChildProcess;
|
|
175
|
+
private pending: Map<string, { resolve: Function; reject: Function }>;
|
|
176
|
+
|
|
177
|
+
constructor(config: MCPServerConfig);
|
|
178
|
+
|
|
179
|
+
// Initialize connection
|
|
180
|
+
async initialize(): Promise<{ capabilities: any; serverInfo: any }>;
|
|
181
|
+
|
|
182
|
+
// List available tools
|
|
183
|
+
async listTools(): Promise<MCPTool[]>;
|
|
184
|
+
|
|
185
|
+
// Call a tool
|
|
186
|
+
async callTool(name: string, arguments: any): Promise<any>;
|
|
187
|
+
|
|
188
|
+
// List resources
|
|
189
|
+
async listResources(): Promise<MCPResource[]>;
|
|
190
|
+
|
|
191
|
+
// Read a resource
|
|
192
|
+
async readResource(uri: string): Promise<any>;
|
|
193
|
+
|
|
194
|
+
// List prompts
|
|
195
|
+
async listPrompts(): Promise<MCPPrompt[]>;
|
|
196
|
+
|
|
197
|
+
// Get a prompt
|
|
198
|
+
async getPrompt(name: string, arguments?: any): Promise<any>;
|
|
199
|
+
|
|
200
|
+
// Close connection
|
|
201
|
+
async close(): Promise<void>;
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Integration with Tool Registry
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// Bridge MCP tools to native tool format
|
|
209
|
+
function mcpToolToNativeTool(mcpTool: MCPTool, mcpManager: MCPManager): Tool<any> {
|
|
210
|
+
return {
|
|
211
|
+
name: `mcp__${mcpTool.serverName}__${mcpTool.name}`,
|
|
212
|
+
description: mcpTool.description,
|
|
213
|
+
parameters: jsonSchemaToZod(mcpTool.inputSchema),
|
|
214
|
+
execute: async (input, context) => {
|
|
215
|
+
const result = await mcpManager.executeTool(
|
|
216
|
+
mcpTool.serverName,
|
|
217
|
+
mcpTool.name,
|
|
218
|
+
input
|
|
219
|
+
);
|
|
220
|
+
return { success: true, output: result };
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### File Changes
|
|
227
|
+
|
|
228
|
+
| File | Action | Description |
|
|
229
|
+
|------|--------|-------------|
|
|
230
|
+
| `src/mcp/types.ts` | Create | MCP type definitions |
|
|
231
|
+
| `src/mcp/mcp-manager.ts` | Create | MCP server management |
|
|
232
|
+
| `src/mcp/protocol.ts` | Create | MCP protocol implementation |
|
|
233
|
+
| `src/mcp/connection.ts` | Create | Server connection handling |
|
|
234
|
+
| `src/mcp/tool-bridge.ts` | Create | MCP to native tool bridge |
|
|
235
|
+
| `src/mcp/index.ts` | Create | Module exports |
|
|
236
|
+
| `src/tools/registry.ts` | Modify | Register MCP tools |
|
|
237
|
+
| `src/agent/agent.ts` | Modify | Initialize MCP on startup |
|
|
238
|
+
| `src/cli/commands/mcp.ts` | Create | /mcp command |
|
|
239
|
+
|
|
240
|
+
## User Experience
|
|
241
|
+
|
|
242
|
+
### Adding MCP Server
|
|
243
|
+
```
|
|
244
|
+
> /mcp add github
|
|
245
|
+
|
|
246
|
+
Enter GitHub token: ********
|
|
247
|
+
|
|
248
|
+
✓ Added MCP server: github
|
|
249
|
+
Available tools:
|
|
250
|
+
• mcp__github__create_issue
|
|
251
|
+
• mcp__github__list_repos
|
|
252
|
+
• mcp__github__get_file
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Listing Servers
|
|
256
|
+
```
|
|
257
|
+
> /mcp list
|
|
258
|
+
|
|
259
|
+
MCP Servers:
|
|
260
|
+
┌────────────┬───────────┬─────────────────────────┐
|
|
261
|
+
│ Server │ Status │ Tools │
|
|
262
|
+
├────────────┼───────────┼─────────────────────────┤
|
|
263
|
+
│ github │ connected │ 5 tools │
|
|
264
|
+
│ jira │ connected │ 8 tools │
|
|
265
|
+
│ filesystem │ error │ Connection failed │
|
|
266
|
+
└────────────┴───────────┴─────────────────────────┘
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Using MCP Tools
|
|
270
|
+
```
|
|
271
|
+
User: Create a GitHub issue for this bug
|
|
272
|
+
|
|
273
|
+
Agent: I'll create a GitHub issue using the MCP server.
|
|
274
|
+
[mcp__github__create_issue]
|
|
275
|
+
|
|
276
|
+
✓ Created issue: https://github.com/user/repo/issues/42
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Configuration File
|
|
280
|
+
`.mycode/mcp.json`:
|
|
281
|
+
```json
|
|
282
|
+
{
|
|
283
|
+
"servers": {
|
|
284
|
+
"github": {
|
|
285
|
+
"command": "npx",
|
|
286
|
+
"args": ["-y", "@modelcontextprotocol/server-github"],
|
|
287
|
+
"env": {
|
|
288
|
+
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
"slack": {
|
|
292
|
+
"command": "npx",
|
|
293
|
+
"args": ["-y", "@modelcontextprotocol/server-slack"],
|
|
294
|
+
"env": {
|
|
295
|
+
"SLACK_TOKEN": "${SLACK_TOKEN}"
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Alternatives Considered
|
|
303
|
+
|
|
304
|
+
### Alternative 1: Custom Plugin Format
|
|
305
|
+
Define our own plugin/extension format.
|
|
306
|
+
|
|
307
|
+
**Pros**: Full control, optimized for our use case
|
|
308
|
+
**Cons**: No ecosystem, incompatible with Claude Code
|
|
309
|
+
**Decision**: Rejected - MCP provides ecosystem benefits
|
|
310
|
+
|
|
311
|
+
### Alternative 2: HTTP-Only Integrations
|
|
312
|
+
Only support HTTP-based tool servers.
|
|
313
|
+
|
|
314
|
+
**Pros**: Simpler, no process management
|
|
315
|
+
**Cons**: Missing local tools, extra latency
|
|
316
|
+
**Decision**: Rejected - Process-based is more flexible
|
|
317
|
+
|
|
318
|
+
### Alternative 3: Built-in Integrations
|
|
319
|
+
Hardcode popular integrations (GitHub, Jira).
|
|
320
|
+
|
|
321
|
+
**Pros**: Better integration, no setup
|
|
322
|
+
**Cons**: Limited extensibility, maintenance burden
|
|
323
|
+
**Decision**: Rejected - MCP is more scalable
|
|
324
|
+
|
|
325
|
+
## Security Considerations
|
|
326
|
+
|
|
327
|
+
1. **Process Isolation**: MCP servers run as separate processes
|
|
328
|
+
2. **Credential Security**: Secure handling of API keys/tokens
|
|
329
|
+
3. **Permission Control**: Control which MCP tools are allowed
|
|
330
|
+
4. **Environment Variables**: Safe expansion of env vars
|
|
331
|
+
5. **Sandboxing**: Consider sandboxing MCP server processes
|
|
332
|
+
6. **Audit Logging**: Log MCP tool invocations
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
// Secure environment variable expansion
|
|
336
|
+
function expandEnvVars(env: Record<string, string>): Record<string, string> {
|
|
337
|
+
const result: Record<string, string> = {};
|
|
338
|
+
for (const [key, value] of Object.entries(env)) {
|
|
339
|
+
if (value.startsWith('${') && value.endsWith('}')) {
|
|
340
|
+
const envName = value.slice(2, -1);
|
|
341
|
+
result[key] = process.env[envName] || '';
|
|
342
|
+
} else {
|
|
343
|
+
result[key] = value;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return result;
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Testing Strategy
|
|
351
|
+
|
|
352
|
+
1. **Unit Tests**:
|
|
353
|
+
- Protocol message handling
|
|
354
|
+
- Tool bridging
|
|
355
|
+
- Configuration parsing
|
|
356
|
+
|
|
357
|
+
2. **Integration Tests**:
|
|
358
|
+
- Server lifecycle (start/stop)
|
|
359
|
+
- Tool execution
|
|
360
|
+
- Error handling
|
|
361
|
+
|
|
362
|
+
3. **Manual Testing**:
|
|
363
|
+
- Real MCP servers
|
|
364
|
+
- Various server types
|
|
365
|
+
- Network/process failures
|
|
366
|
+
|
|
367
|
+
## Migration Path
|
|
368
|
+
|
|
369
|
+
1. **Phase 1**: Core MCP protocol implementation
|
|
370
|
+
2. **Phase 2**: Tool bridging and registration
|
|
371
|
+
3. **Phase 3**: /mcp command for server management
|
|
372
|
+
4. **Phase 4**: Resource and prompt support
|
|
373
|
+
5. **Phase 5**: Permission controls and UI improvements
|
|
374
|
+
|
|
375
|
+
No breaking changes to existing functionality.
|
|
376
|
+
|
|
377
|
+
## References
|
|
378
|
+
|
|
379
|
+
- [Model Context Protocol Specification](https://spec.modelcontextprotocol.io/)
|
|
380
|
+
- [MCP GitHub Repository](https://github.com/modelcontextprotocol)
|
|
381
|
+
- [Claude Code MCP Documentation](https://code.claude.com/docs/en/mcp)
|
|
382
|
+
- [Building MCP Servers](https://modelcontextprotocol.io/quickstart)
|