@kasarlabs/mcp-doc-mcp 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/LICENSE +21 -0
- package/README.md +202 -0
- package/bin/mcp-doc-mcp.js +2 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +57 -0
- package/build/index.js.map +1 -0
- package/build/resources/architecture.md +369 -0
- package/build/resources/capabilities.md +573 -0
- package/build/resources/help.md +147 -0
- package/build/resources/projects.md +104 -0
- package/build/schemas/index.d.ts +35 -0
- package/build/schemas/index.js +42 -0
- package/build/schemas/index.js.map +1 -0
- package/build/tools/explainArchitecture.d.ts +11 -0
- package/build/tools/explainArchitecture.js +21 -0
- package/build/tools/explainArchitecture.js.map +1 -0
- package/build/tools/getHelp.d.ts +11 -0
- package/build/tools/getHelp.js +21 -0
- package/build/tools/getHelp.js.map +1 -0
- package/build/tools/listCapabilities.d.ts +11 -0
- package/build/tools/listCapabilities.js +21 -0
- package/build/tools/listCapabilities.js.map +1 -0
- package/build/tools/suggestProjects.d.ts +11 -0
- package/build/tools/suggestProjects.js +21 -0
- package/build/tools/suggestProjects.js.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kasar Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# MCP Doc Server
|
|
2
|
+
|
|
3
|
+
Documentation and discovery MCP server for Ask Starknet. This MCP provides tools to explore Ask Starknet's architecture, capabilities, project ideas, and usage guide.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Quick Start Guide**: Get help on how to use Ask Starknet with setup instructions and best practices
|
|
8
|
+
- **Architecture Explanation**: Understand how Ask Starknet's unified router and MCP servers work together
|
|
9
|
+
- **Capabilities Listing**: Discover all available MCPs organized by domains (wallets, DeFi, blockchain, dev-tools, special)
|
|
10
|
+
- **Project Ideas**: Get inspired with project ideas that can be built using Ask Starknet
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx -y @kasarlabs/mcp-doc-mcp
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Available Tools
|
|
19
|
+
|
|
20
|
+
### 1. `mcp_doc_help`
|
|
21
|
+
|
|
22
|
+
Get comprehensive help on using Ask Starknet, including quick start guide, setup instructions, best practices, and troubleshooting.
|
|
23
|
+
|
|
24
|
+
**Parameters:**
|
|
25
|
+
|
|
26
|
+
None (empty object)
|
|
27
|
+
|
|
28
|
+
**Example:**
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Response:**
|
|
35
|
+
|
|
36
|
+
Returns a markdown-formatted help guide with:
|
|
37
|
+
|
|
38
|
+
- What is Ask Starknet
|
|
39
|
+
- Quick start examples
|
|
40
|
+
- Setup instructions (minimal and full)
|
|
41
|
+
- Best practices
|
|
42
|
+
- Troubleshooting tips
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"status": "success",
|
|
47
|
+
"data": "# Ask Starknet Help Guide\n\nWelcome to Ask Starknet!..."
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 2. `mcp_doc_explain_architecture`
|
|
52
|
+
|
|
53
|
+
Explains the Ask Starknet architecture and how it works.
|
|
54
|
+
|
|
55
|
+
**Parameters:**
|
|
56
|
+
|
|
57
|
+
- `topic` (optional): `"router"` | `"mcps"` | `"interaction"` | `"all"`
|
|
58
|
+
|
|
59
|
+
**Example:**
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"topic": "router"
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Response:**
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"status": "success",
|
|
72
|
+
"data": {
|
|
73
|
+
"overview": "...",
|
|
74
|
+
"unifiedRouter": {
|
|
75
|
+
"description": "...",
|
|
76
|
+
"howItWorks": "...",
|
|
77
|
+
"technologies": [...]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 3. `mcp_doc_list_capabilities`
|
|
84
|
+
|
|
85
|
+
Lists all Ask Starknet capabilities organized by domains.
|
|
86
|
+
|
|
87
|
+
**Parameters:**
|
|
88
|
+
|
|
89
|
+
- `domain` (optional): `"wallets"` | `"defi"` | `"blockchain"` | `"dev-tools"` | `"special"` | `"all"`
|
|
90
|
+
- `mcp` (optional): Filter by specific MCP name (e.g., `"avnu"`, `"erc20"`)
|
|
91
|
+
|
|
92
|
+
**Example:**
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"domain": "defi"
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Response:**
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"status": "success",
|
|
105
|
+
"data": {
|
|
106
|
+
"domains": {
|
|
107
|
+
"defi": {
|
|
108
|
+
"description": "...",
|
|
109
|
+
"mcps": {
|
|
110
|
+
"avnu": {
|
|
111
|
+
"description": "...",
|
|
112
|
+
"tools": [...],
|
|
113
|
+
"expertise": "...",
|
|
114
|
+
"toolCount": 2
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"statistics": {
|
|
120
|
+
"totalMCPs": 20,
|
|
121
|
+
"totalTools": 150,
|
|
122
|
+
"mcpsByDomain": {...}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 4. `mcp_doc_suggest_projects`
|
|
129
|
+
|
|
130
|
+
Suggests project ideas that can be built with Ask Starknet.
|
|
131
|
+
|
|
132
|
+
**Parameters:**
|
|
133
|
+
|
|
134
|
+
- `domain` (optional): `"defi"` | `"nft"` | `"trading"` | `"automation"` | `"analytics"` | `"gaming"` | `"all"`
|
|
135
|
+
- `mcps` (optional): Filter projects using specific MCPs (e.g., `["avnu", "ekubo"]`)
|
|
136
|
+
|
|
137
|
+
**Example:**
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"domain": "defi",
|
|
142
|
+
"mcps": ["avnu", "ekubo"]
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Response:**
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"status": "success",
|
|
151
|
+
"data": {
|
|
152
|
+
"projects": [
|
|
153
|
+
{
|
|
154
|
+
"name": "Multi-DEX Swap Aggregator",
|
|
155
|
+
"description": "...",
|
|
156
|
+
"domain": "defi",
|
|
157
|
+
"requiredMCPs": ["avnu", "ekubo", "fibrous"],
|
|
158
|
+
"features": [...]
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
"totalProjects": 5
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Domains
|
|
167
|
+
|
|
168
|
+
Ask Starknet organizes MCPs into the following domains:
|
|
169
|
+
|
|
170
|
+
- **Wallets**: `argent`, `braavos`, `okx`, `openzeppelin`
|
|
171
|
+
- **DeFi**: `avnu`, `ekubo`, `endurfi`, `extended`, `fibrous`, `opus`, `vesu`, `unruggable`
|
|
172
|
+
- **Blockchain**: `erc20`, `erc721`, `transaction`, `starknet-rpc`, `contract`
|
|
173
|
+
- **Dev Tools**: `scarb`, `cairo-coder`
|
|
174
|
+
- **Special**: `artpeace`
|
|
175
|
+
|
|
176
|
+
## Development
|
|
177
|
+
|
|
178
|
+
### Build
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
pnpm install
|
|
182
|
+
pnpm build
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
The build process compiles TypeScript and copies resource files to the build directory.
|
|
186
|
+
|
|
187
|
+
## Architecture
|
|
188
|
+
|
|
189
|
+
This MCP is designed to be completely standalone with no blockchain dependencies. It uses:
|
|
190
|
+
|
|
191
|
+
- **Static resources**: Help guide, architecture docs, and capabilities are stored as markdown files in `src/resources/`
|
|
192
|
+
- **Static project ideas**: Curated list of project ideas
|
|
193
|
+
- **No external dependencies**: All data is bundled with the MCP for offline access
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT
|
|
198
|
+
|
|
199
|
+
## Support
|
|
200
|
+
|
|
201
|
+
- GitHub Issues: [Create an issue](https://github.com/kasarlabs/ask-starknet/issues)
|
|
202
|
+
- Documentation: [docs.kasar.io](https://docs.kasar.io)
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import * as dotenv from 'dotenv';
|
|
5
|
+
import { registerToolsWithServer } from '@kasarlabs/ask-starknet-core';
|
|
6
|
+
import { explainArchitecture } from './tools/explainArchitecture.js';
|
|
7
|
+
import { listCapabilities } from './tools/listCapabilities.js';
|
|
8
|
+
import { suggestProjects } from './tools/suggestProjects.js';
|
|
9
|
+
import { getHelp } from './tools/getHelp.js';
|
|
10
|
+
import { explainArchitectureSchema, listCapabilitiesSchema, suggestProjectsSchema, getHelpSchema, } from './schemas/index.js';
|
|
11
|
+
dotenv.config();
|
|
12
|
+
const server = new McpServer({
|
|
13
|
+
name: 'mcp-doc-mcp',
|
|
14
|
+
version: '0.1.0',
|
|
15
|
+
});
|
|
16
|
+
const registerTools = (DocsToolRegistry) => {
|
|
17
|
+
DocsToolRegistry.push({
|
|
18
|
+
name: 'mcp_doc_explain_architecture',
|
|
19
|
+
description: 'Explain the Ask Starknet architecture, unified router AI-powered routing, MCP servers structure, and how they interact together',
|
|
20
|
+
schema: explainArchitectureSchema,
|
|
21
|
+
execute: explainArchitecture,
|
|
22
|
+
});
|
|
23
|
+
DocsToolRegistry.push({
|
|
24
|
+
name: 'mcp_doc_list_capabilities',
|
|
25
|
+
description: 'List all Ask Starknet capabilities organized by domains (wallets, DeFi, blockchain, dev-tools, special) with available MCPs and their tools',
|
|
26
|
+
schema: listCapabilitiesSchema,
|
|
27
|
+
execute: listCapabilities,
|
|
28
|
+
});
|
|
29
|
+
DocsToolRegistry.push({
|
|
30
|
+
name: 'mcp_doc_suggest_projects',
|
|
31
|
+
description: 'Suggest project ideas that can be built with Ask Starknet, filtered by domain or required MCPs',
|
|
32
|
+
schema: suggestProjectsSchema,
|
|
33
|
+
execute: suggestProjects,
|
|
34
|
+
});
|
|
35
|
+
DocsToolRegistry.push({
|
|
36
|
+
name: 'mcp_doc_help',
|
|
37
|
+
description: 'Get help on how to use Ask Starknet: quick start guide, setup instructions, capabilities overview, and troubleshooting',
|
|
38
|
+
schema: getHelpSchema,
|
|
39
|
+
execute: getHelp,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
export const RegisterToolInServer = async () => {
|
|
43
|
+
const tools = [];
|
|
44
|
+
registerTools(tools);
|
|
45
|
+
await registerToolsWithServer(server, tools);
|
|
46
|
+
};
|
|
47
|
+
async function main() {
|
|
48
|
+
const transport = new StdioServerTransport();
|
|
49
|
+
await RegisterToolInServer();
|
|
50
|
+
await server.connect(transport);
|
|
51
|
+
console.error('MCP Doc Server running on stdio');
|
|
52
|
+
}
|
|
53
|
+
main().catch((error) => {
|
|
54
|
+
console.error('Fatal error in main():', error);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAW,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAC3B,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,OAAO;CACjB,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,CAAC,gBAA2B,EAAE,EAAE;IACpD,gBAAgB,CAAC,IAAI,CAAC;QACpB,IAAI,EAAE,8BAA8B;QACpC,WAAW,EACT,iIAAiI;QACnI,MAAM,EAAE,yBAAyB;QACjC,OAAO,EAAE,mBAAmB;KAC7B,CAAC,CAAC;IAEH,gBAAgB,CAAC,IAAI,CAAC;QACpB,IAAI,EAAE,2BAA2B;QACjC,WAAW,EACT,6IAA6I;QAC/I,MAAM,EAAE,sBAAsB;QAC9B,OAAO,EAAE,gBAAgB;KAC1B,CAAC,CAAC;IAEH,gBAAgB,CAAC,IAAI,CAAC;QACpB,IAAI,EAAE,0BAA0B;QAChC,WAAW,EACT,gGAAgG;QAClG,MAAM,EAAE,qBAAqB;QAC7B,OAAO,EAAE,eAAe;KACzB,CAAC,CAAC;IAEH,gBAAgB,CAAC,IAAI,CAAC;QACpB,IAAI,EAAE,cAAc;QACpB,WAAW,EACT,wHAAwH;QAC1H,MAAM,EAAE,aAAa;QACrB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,IAAI,EAAE;IAC7C,MAAM,KAAK,GAAc,EAAE,CAAC;IAC5B,aAAa,CAAC,KAAK,CAAC,CAAC;IACrB,MAAM,uBAAuB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC,CAAC;AAEF,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAE7C,MAAM,oBAAoB,EAAE,CAAC;IAC7B,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;AACnD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;IAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
# Ask Starknet Architecture
|
|
2
|
+
|
|
3
|
+
Ask Starknet is built on a modular, AI-powered architecture that provides intelligent routing to specialized MCP servers for Starknet blockchain operations.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The system consists of three main layers:
|
|
8
|
+
|
|
9
|
+
1. **Unified MCP Router** - AI-powered request routing
|
|
10
|
+
2. **Specialized MCP Servers** - Domain-specific tool execution
|
|
11
|
+
3. **Core Utilities** - Shared interfaces and utilities
|
|
12
|
+
|
|
13
|
+
## Architecture Diagram
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
17
|
+
│ User Request │
|
|
18
|
+
│ (Natural Language Input) │
|
|
19
|
+
└────────────────────────┬────────────────────────────────────┘
|
|
20
|
+
│
|
|
21
|
+
v
|
|
22
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
23
|
+
│ Unified MCP Router │
|
|
24
|
+
│ (packages/mcp/) │
|
|
25
|
+
│ │
|
|
26
|
+
│ ┌───────────────────────────────────────────────────────┐ │
|
|
27
|
+
│ │ LangGraph AI-Powered Routing │ │
|
|
28
|
+
│ │ - Selector Agent: Analyzes request intent │ │
|
|
29
|
+
│ │ - Specialized Agent Dispatcher: Routes to MCP │ │
|
|
30
|
+
│ └───────────────────────────────────────────────────────┘ │
|
|
31
|
+
└────────────────────────┬────────────────────────────────────┘
|
|
32
|
+
│
|
|
33
|
+
v
|
|
34
|
+
┌───────────────┴───────────────┐
|
|
35
|
+
│ │
|
|
36
|
+
┌────v────┐ ┌────v────┐
|
|
37
|
+
│ Wallet │ │ DeFi │
|
|
38
|
+
│ MCPs │ │ MCPs │
|
|
39
|
+
└────┬────┘ └────┬────┘
|
|
40
|
+
│ │
|
|
41
|
+
┌────v────────┐ ┌──────v──────┐
|
|
42
|
+
│ • argent │ │ • avnu │
|
|
43
|
+
│ • braavos │ │ • ekubo │
|
|
44
|
+
│ • okx │ │ • fibrous │
|
|
45
|
+
│ • openzeppelin│ │ • opus │
|
|
46
|
+
└─────────────┘ │ • vesu │
|
|
47
|
+
│ • endurfi │
|
|
48
|
+
│ • extended │
|
|
49
|
+
│ • unruggable│
|
|
50
|
+
└─────────────┘
|
|
51
|
+
│ │
|
|
52
|
+
v v
|
|
53
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
54
|
+
│ Starknet Blockchain │
|
|
55
|
+
└─────────────────────────────────────────────────────────────┘
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Components
|
|
59
|
+
|
|
60
|
+
### 1. Unified MCP Router (`packages/mcp/`)
|
|
61
|
+
|
|
62
|
+
The router is the entry point that orchestrates the entire system using LangChain/LangGraph.
|
|
63
|
+
|
|
64
|
+
**Key Features:**
|
|
65
|
+
|
|
66
|
+
- **AI-Powered Analysis:** Uses LLM to understand user intent
|
|
67
|
+
- **Automatic Routing:** Selects the most appropriate specialized MCP
|
|
68
|
+
- **State Management:** Tracks conversation history and context
|
|
69
|
+
- **Environment Propagation:** Dynamically passes required env vars to specialized MCPs
|
|
70
|
+
|
|
71
|
+
**Required Environment Variables:**
|
|
72
|
+
|
|
73
|
+
- At least one of: `ANTHROPIC_API_KEY`, `GEMINI_API_KEY`, `OPENAI_API_KEY`
|
|
74
|
+
- All environment variables required by specialized MCPs (dynamically loaded)
|
|
75
|
+
|
|
76
|
+
**Core Files:**
|
|
77
|
+
|
|
78
|
+
- `src/graph/graph.ts` - LangGraph workflow definition
|
|
79
|
+
- `src/graph/agents/selector.ts` - Agent selection logic
|
|
80
|
+
- `src/graph/agents/specialized.ts` - Specialized MCP execution
|
|
81
|
+
- `src/graph/mcps/utilities.ts` - MCP configuration loading
|
|
82
|
+
- `mcps.json` - Central registry of all MCPs and their configurations
|
|
83
|
+
|
|
84
|
+
### 2. Specialized MCP Servers (`packages/mcps/`)
|
|
85
|
+
|
|
86
|
+
Each specialized MCP server focuses on a specific domain or protocol.
|
|
87
|
+
|
|
88
|
+
**Standard Structure:**
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
packages/mcps/<mcp-name>/
|
|
92
|
+
├── src/
|
|
93
|
+
│ ├── tools/ # Individual tool implementations
|
|
94
|
+
│ ├── schemas/ # Zod validation schemas
|
|
95
|
+
│ ├── lib/ # Utilities, types, constants, ABIs
|
|
96
|
+
│ └── index.ts # MCP server setup and tool registration
|
|
97
|
+
├── bin/
|
|
98
|
+
│ └── <mcp-name>.js # Executable entry point
|
|
99
|
+
└── package.json
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Tool Response Format:**
|
|
103
|
+
All tools return JSON strings with consistent structure:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
{
|
|
107
|
+
status: 'success' | 'failure',
|
|
108
|
+
data?: any, // For successful operations
|
|
109
|
+
error?: string // For failures
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Example MCPs by Domain:**
|
|
114
|
+
|
|
115
|
+
**Wallets:**
|
|
116
|
+
|
|
117
|
+
- `argent` - Argent X wallet creation and deployment
|
|
118
|
+
- `braavos` - Braavos wallet operations
|
|
119
|
+
- `okx` - OKX wallet integration
|
|
120
|
+
- `openzeppelin` - OpenZeppelin account contracts
|
|
121
|
+
|
|
122
|
+
**DeFi:**
|
|
123
|
+
|
|
124
|
+
- `avnu` - DEX aggregator for optimal swap routes
|
|
125
|
+
- `ekubo` - Concentrated liquidity AMM
|
|
126
|
+
- `fibrous` - Multi-DEX swap routing
|
|
127
|
+
- `opus` - CDP (Collateralized Debt Position) and borrowing
|
|
128
|
+
- `vesu` - Lending and yield farming
|
|
129
|
+
- `endurfi` - Liquid staking (xSTRK, xyWBTC)
|
|
130
|
+
- `extended` - Perpetuals trading with leverage
|
|
131
|
+
- `unruggable` - Memecoin creation and liquidity locking
|
|
132
|
+
|
|
133
|
+
**Blockchain Operations:**
|
|
134
|
+
|
|
135
|
+
- `erc20` - Token transfers, approvals, balances
|
|
136
|
+
- `erc721` - NFT operations
|
|
137
|
+
- `starknet-rpc` - Direct RPC calls to Starknet
|
|
138
|
+
- `transaction` - Transaction simulation and monitoring
|
|
139
|
+
- `contract` - Smart contract declaration and deployment
|
|
140
|
+
|
|
141
|
+
**Development Tools:**
|
|
142
|
+
|
|
143
|
+
- `scarb` - Cairo compilation and proving
|
|
144
|
+
- `cairo-coder` - AI-powered Cairo development assistance
|
|
145
|
+
- `mcp-doc` - Documentation and help system
|
|
146
|
+
|
|
147
|
+
**Special:**
|
|
148
|
+
|
|
149
|
+
- `artpeace` - Collaborative pixel art canvas
|
|
150
|
+
|
|
151
|
+
### 3. Core Package (`packages/core/`)
|
|
152
|
+
|
|
153
|
+
Provides shared utilities and interfaces used across all MCPs.
|
|
154
|
+
|
|
155
|
+
**Key Exports:**
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// Tool interface definition
|
|
159
|
+
export interface mcpTool<P = any> {
|
|
160
|
+
name: string;
|
|
161
|
+
description: string;
|
|
162
|
+
schema?: z.AnyZodObject;
|
|
163
|
+
execute: (params: P) => Promise<unknown>;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Utility to register tools with MCP server
|
|
167
|
+
export function registerToolsWithServer(
|
|
168
|
+
server: McpServer,
|
|
169
|
+
tools: mcpTool[]
|
|
170
|
+
): Promise<void>;
|
|
171
|
+
|
|
172
|
+
// Onchain read utilities
|
|
173
|
+
export function getOnchainRead(): {
|
|
174
|
+
provider: RpcProvider;
|
|
175
|
+
account: Account;
|
|
176
|
+
};
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Request Flow
|
|
180
|
+
|
|
181
|
+
### Step 1: User Request
|
|
182
|
+
|
|
183
|
+
User submits a natural language request through their MCP client (e.g., Claude Desktop).
|
|
184
|
+
|
|
185
|
+
### Step 2: Router Analysis
|
|
186
|
+
|
|
187
|
+
The unified router receives the request and uses the **Selector Agent**:
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
// From selector.ts
|
|
191
|
+
const selectorAgent = async (state) => {
|
|
192
|
+
// Analyze user input with LLM
|
|
193
|
+
const response = await llm.invoke([
|
|
194
|
+
systemPrompt, // Contains available agents and their expertise
|
|
195
|
+
userInput, // User's request
|
|
196
|
+
]);
|
|
197
|
+
|
|
198
|
+
// Returns selected agent name or END
|
|
199
|
+
return { next: selectedAgent };
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Step 3: Specialized Execution
|
|
204
|
+
|
|
205
|
+
The **Specialized Agent** loads the selected MCP and executes tools:
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// From specialized.ts
|
|
209
|
+
const specializedNode = async (state) => {
|
|
210
|
+
// Load MCP client for selected agent
|
|
211
|
+
const client = new MultiServerMCPClient({
|
|
212
|
+
[agentName]: getMCPClientConfig(agentName, env),
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// Get tools and bind to LLM
|
|
216
|
+
const tools = await client.getTools();
|
|
217
|
+
const model = llm.bindTools(tools);
|
|
218
|
+
|
|
219
|
+
// Execute with LLM
|
|
220
|
+
const response = await model.invoke(messages);
|
|
221
|
+
|
|
222
|
+
// Execute tools if needed
|
|
223
|
+
if (response.tool_calls) {
|
|
224
|
+
const toolResults = await toolNode.invoke({ messages });
|
|
225
|
+
const finalResponse = await model.invoke([...messages, toolResults]);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return { messages: [finalResponse] };
|
|
229
|
+
};
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Step 4: Tool Execution
|
|
233
|
+
|
|
234
|
+
The specialized MCP server executes the requested tools and returns results.
|
|
235
|
+
|
|
236
|
+
### Step 5: Response
|
|
237
|
+
|
|
238
|
+
Results are formatted and returned to the user through the router.
|
|
239
|
+
|
|
240
|
+
## Configuration Management
|
|
241
|
+
|
|
242
|
+
### MCP Registry (`packages/mcp/mcps.json`)
|
|
243
|
+
|
|
244
|
+
Central configuration file defining all available MCPs:
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"mcp-name": {
|
|
249
|
+
"client": {
|
|
250
|
+
"command": "npx",
|
|
251
|
+
"args": ["-y", "@kasarlabs/mcp-name-mcp"],
|
|
252
|
+
"transport": "stdio",
|
|
253
|
+
"env": {
|
|
254
|
+
"REQUIRED_VAR": "",
|
|
255
|
+
"OPTIONAL_VAR": ""
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
"description": "What this MCP does",
|
|
259
|
+
"promptInfo": {
|
|
260
|
+
"expertise": "Domain expertise description",
|
|
261
|
+
"tools": ["tool_name_1", "tool_name_2"]
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Dynamic Environment Loading
|
|
268
|
+
|
|
269
|
+
The router automatically:
|
|
270
|
+
|
|
271
|
+
1. Loads all environment variables from the host
|
|
272
|
+
2. Validates required variables for each MCP
|
|
273
|
+
3. Passes only necessary variables to each specialized MCP
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
// From utilities.ts
|
|
277
|
+
export const getMCPClientConfig = (serverName, env) => {
|
|
278
|
+
const serverInfo = getMcpInfo(serverName);
|
|
279
|
+
const config = { ...serverInfo.client };
|
|
280
|
+
|
|
281
|
+
// Inject environment variables
|
|
282
|
+
for (const envVar in serverInfo.client.env) {
|
|
283
|
+
if (env[envVar]) {
|
|
284
|
+
config.env[envVar] = env[envVar];
|
|
285
|
+
} else {
|
|
286
|
+
throw new Error(`Missing: ${envVar}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return config;
|
|
291
|
+
};
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## State Management
|
|
295
|
+
|
|
296
|
+
Uses LangGraph's state annotation for type-safe state management:
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
export const GraphAnnotation = Annotation.Root({
|
|
300
|
+
messages: Annotation<BaseMessage[]>({
|
|
301
|
+
reducer: messagesStateReducer,
|
|
302
|
+
default: () => [],
|
|
303
|
+
}),
|
|
304
|
+
next: Annotation<AgentName>({
|
|
305
|
+
reducer: (x, y) => y ?? x,
|
|
306
|
+
default: () => END,
|
|
307
|
+
}),
|
|
308
|
+
mcpEnvironment: Annotation<MCPEnvironment>({
|
|
309
|
+
reducer: (x, y) => y ?? x,
|
|
310
|
+
}),
|
|
311
|
+
routingInfo: Annotation<{
|
|
312
|
+
reasoning?: string;
|
|
313
|
+
timestamp?: string;
|
|
314
|
+
}>({
|
|
315
|
+
reducer: (x, y) => ({ ...x, ...y }),
|
|
316
|
+
default: () => ({}),
|
|
317
|
+
}),
|
|
318
|
+
});
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
## Error Handling
|
|
322
|
+
|
|
323
|
+
### Router Level
|
|
324
|
+
|
|
325
|
+
- Validates LLM API keys on startup
|
|
326
|
+
- Catches graph execution errors
|
|
327
|
+
- Returns structured error responses
|
|
328
|
+
|
|
329
|
+
### Specialized MCP Level
|
|
330
|
+
|
|
331
|
+
- Validates environment variables before initialization
|
|
332
|
+
- Handles tool execution errors
|
|
333
|
+
- Returns error status in consistent format
|
|
334
|
+
|
|
335
|
+
### Tool Level
|
|
336
|
+
|
|
337
|
+
- Input validation with Zod schemas
|
|
338
|
+
- Try-catch error handling
|
|
339
|
+
- Detailed error messages
|
|
340
|
+
|
|
341
|
+
## Extensibility
|
|
342
|
+
|
|
343
|
+
### Adding New MCPs
|
|
344
|
+
|
|
345
|
+
1. **Create the MCP server** following the standard structure
|
|
346
|
+
2. **Register in `mcps.json`** with configuration
|
|
347
|
+
3. **Update generated types** with `pnpm generate:mcps-data`
|
|
348
|
+
4. **Build and publish** the package
|
|
349
|
+
|
|
350
|
+
The router will automatically:
|
|
351
|
+
|
|
352
|
+
- Discover the new MCP
|
|
353
|
+
- Include it in routing decisions
|
|
354
|
+
- Load required environment variables
|
|
355
|
+
- Make tools available to users
|
|
356
|
+
|
|
357
|
+
## Performance Considerations
|
|
358
|
+
|
|
359
|
+
- **Lazy Loading:** MCPs are only loaded when needed
|
|
360
|
+
- **Caching:** LLM responses can be cached for repeated queries
|
|
361
|
+
- **Parallel Execution:** Independent operations can run in parallel
|
|
362
|
+
- **Token Optimization:** Minimal context sent to LLMs
|
|
363
|
+
|
|
364
|
+
## Security
|
|
365
|
+
|
|
366
|
+
- **Environment Isolation:** Each MCP only receives necessary env vars
|
|
367
|
+
- **Private Key Protection:** Never logged or exposed
|
|
368
|
+
- **Input Validation:** All inputs validated with Zod schemas
|
|
369
|
+
- **Sandboxed Execution:** MCPs run in isolated stdio processes
|