@utdk/mcp 0.1.0-dev.646adf4 → 0.1.0-dev.6750ba0
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/dist/server.js +157 -162
- package/dist/server.js.map +1 -1
- package/package.json +20 -20
- package/src/server.ts +173 -180
package/dist/server.js
CHANGED
|
@@ -29,15 +29,6 @@ import { searchTools, groupTools } from "./search.js";
|
|
|
29
29
|
* Ensure the input schema is a valid MCP tool inputSchema (type: "object").
|
|
30
30
|
*/
|
|
31
31
|
function normalizeInputSchema(schema) {
|
|
32
|
-
if (schema["type"] === "object") {
|
|
33
|
-
return {
|
|
34
|
-
type: "object",
|
|
35
|
-
...(schema["properties"]
|
|
36
|
-
? { properties: schema["properties"] }
|
|
37
|
-
: {}),
|
|
38
|
-
...(schema["required"] ? { required: schema["required"] } : {}),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
32
|
return {
|
|
42
33
|
type: "object",
|
|
43
34
|
...(schema["properties"]
|
|
@@ -46,7 +37,154 @@ function normalizeInputSchema(schema) {
|
|
|
46
37
|
...(schema["required"] ? { required: schema["required"] } : {}),
|
|
47
38
|
};
|
|
48
39
|
}
|
|
49
|
-
//
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Meta-tool definitions (served by tools/list)
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
const META_TOOLS = [
|
|
44
|
+
{
|
|
45
|
+
name: "list_tools",
|
|
46
|
+
description: "List available tool names without full schemas. Pass an optional provider to filter results, or group_by to organize by category.",
|
|
47
|
+
inputSchema: {
|
|
48
|
+
type: "object",
|
|
49
|
+
properties: {
|
|
50
|
+
provider: {
|
|
51
|
+
type: "string",
|
|
52
|
+
description: "Filter results to tools from this provider name (e.g. 'github')",
|
|
53
|
+
},
|
|
54
|
+
group_by: {
|
|
55
|
+
type: "string",
|
|
56
|
+
enum: ["provider", "tag"],
|
|
57
|
+
description: "Group results by 'provider' or by OpenAPI 'tag'. When omitted, returns a flat list of names.",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "search_tools",
|
|
64
|
+
description: "Find tools by keyword. Searches tool names, OpenAPI tags, and descriptions using TF-IDF relevance ranking so the LLM can locate relevant tools without browsing the full catalog.",
|
|
65
|
+
inputSchema: {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {
|
|
68
|
+
query: {
|
|
69
|
+
type: "string",
|
|
70
|
+
description: "Natural language or keyword search (all words must appear in name, tags, or description)",
|
|
71
|
+
},
|
|
72
|
+
provider: {
|
|
73
|
+
type: "string",
|
|
74
|
+
description: "Restrict search to tools from this provider name (e.g. 'github')",
|
|
75
|
+
},
|
|
76
|
+
limit: {
|
|
77
|
+
type: "number",
|
|
78
|
+
description: "Maximum number of results to return (default 10)",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
required: ["query"],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "tool_info",
|
|
86
|
+
description: "Get the full schema and metadata for a specific tool by name. Use this after list_tools or search_tools to retrieve the complete input schema before calling the tool.",
|
|
87
|
+
inputSchema: {
|
|
88
|
+
type: "object",
|
|
89
|
+
properties: {
|
|
90
|
+
tool_name: {
|
|
91
|
+
type: "string",
|
|
92
|
+
description: "The MCP tool name (e.g. 'github__repos_list')",
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
required: ["tool_name"],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "call_tool",
|
|
100
|
+
description: "Execute any registered tool by name with the provided arguments. Use tool_info first to get the correct argument schema.",
|
|
101
|
+
inputSchema: {
|
|
102
|
+
type: "object",
|
|
103
|
+
properties: {
|
|
104
|
+
tool_name: {
|
|
105
|
+
type: "string",
|
|
106
|
+
description: "The MCP tool name to execute (e.g. 'github__repos_list')",
|
|
107
|
+
},
|
|
108
|
+
arguments: {
|
|
109
|
+
type: "object",
|
|
110
|
+
description: "Arguments to pass to the tool",
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
required: ["tool_name", "arguments"],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
// ---------------------------------------------------------------------------
|
|
118
|
+
// Meta-tool call handlers
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
function handleListTools(tools, args) {
|
|
121
|
+
const providerFilter = typeof args["provider"] === "string" ? args["provider"] : undefined;
|
|
122
|
+
const groupBy = args["group_by"] === "provider" || args["group_by"] === "tag"
|
|
123
|
+
? args["group_by"]
|
|
124
|
+
: undefined;
|
|
125
|
+
const filtered = providerFilter
|
|
126
|
+
? tools.filter((t) => t.providerName === providerFilter)
|
|
127
|
+
: tools;
|
|
128
|
+
const result = groupBy === "provider" || groupBy === "tag"
|
|
129
|
+
? groupTools(filtered, groupBy)
|
|
130
|
+
: filtered.map((t) => t.mcpName);
|
|
131
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
132
|
+
}
|
|
133
|
+
function handleSearchTools(tools, args) {
|
|
134
|
+
const query = typeof args["query"] === "string" ? args["query"] : "";
|
|
135
|
+
const providerFilter = typeof args["provider"] === "string" ? args["provider"] : undefined;
|
|
136
|
+
const limit = typeof args["limit"] === "number" && args["limit"] > 0 ? Math.floor(args["limit"]) : 10;
|
|
137
|
+
const results = searchTools(tools, query, providerFilter, limit);
|
|
138
|
+
return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] };
|
|
139
|
+
}
|
|
140
|
+
function handleToolInfo(toolMap, args) {
|
|
141
|
+
const requestedName = typeof args["tool_name"] === "string" ? args["tool_name"] : "";
|
|
142
|
+
const tool = toolMap.get(requestedName);
|
|
143
|
+
if (!tool) {
|
|
144
|
+
return {
|
|
145
|
+
isError: true,
|
|
146
|
+
content: [{ type: "text", text: `Unknown tool: ${requestedName}` }],
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
content: [
|
|
151
|
+
{
|
|
152
|
+
type: "text",
|
|
153
|
+
text: JSON.stringify({
|
|
154
|
+
name: tool.mcpName,
|
|
155
|
+
description: tool.description,
|
|
156
|
+
provider: tool.providerName,
|
|
157
|
+
inputSchema: normalizeInputSchema(tool.inputSchema),
|
|
158
|
+
}, null, 2),
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
async function handleCallTool(toolMap, args) {
|
|
164
|
+
const requestedName = typeof args["tool_name"] === "string" ? args["tool_name"] : "";
|
|
165
|
+
const toolArgs = typeof args["arguments"] === "object" && args["arguments"] !== null
|
|
166
|
+
? args["arguments"]
|
|
167
|
+
: {};
|
|
168
|
+
const tool = toolMap.get(requestedName);
|
|
169
|
+
if (!tool) {
|
|
170
|
+
return {
|
|
171
|
+
isError: true,
|
|
172
|
+
content: [{ type: "text", text: `Unknown tool: ${requestedName}` }],
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
const result = await executeTool(tool, toolArgs);
|
|
177
|
+
const text = typeof result === "string" ? result : JSON.stringify(result, null, 2);
|
|
178
|
+
return { content: [{ type: "text", text }] };
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
182
|
+
return {
|
|
183
|
+
isError: true,
|
|
184
|
+
content: [{ type: "text", text: `Error calling ${requestedName}: ${message}` }],
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
50
188
|
// ---------------------------------------------------------------------------
|
|
51
189
|
// MCP Server factory
|
|
52
190
|
// ---------------------------------------------------------------------------
|
|
@@ -60,162 +198,19 @@ function createServer(tools) {
|
|
|
60
198
|
// Build a lookup map for fast dispatch
|
|
61
199
|
const toolMap = new Map(tools.map((t) => [t.mcpName, t]));
|
|
62
200
|
// tools/list — return exactly the 4 meta-tools (no direct provider tool exposure)
|
|
63
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
64
|
-
tools: [
|
|
65
|
-
{
|
|
66
|
-
name: "list_tools",
|
|
67
|
-
description: "List available tool names without full schemas. Pass an optional provider to filter results, or group_by to organize by category.",
|
|
68
|
-
inputSchema: {
|
|
69
|
-
type: "object",
|
|
70
|
-
properties: {
|
|
71
|
-
provider: {
|
|
72
|
-
type: "string",
|
|
73
|
-
description: "Filter results to tools from this provider name (e.g. 'github')",
|
|
74
|
-
},
|
|
75
|
-
group_by: {
|
|
76
|
-
type: "string",
|
|
77
|
-
enum: ["provider", "tag"],
|
|
78
|
-
description: "Group results by 'provider' or by OpenAPI 'tag'. When omitted, returns a flat list of names.",
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
name: "search_tools",
|
|
85
|
-
description: "Find tools by keyword. Searches tool names, OpenAPI tags, and descriptions using TF-IDF relevance ranking so the LLM can locate relevant tools without browsing the full catalog.",
|
|
86
|
-
inputSchema: {
|
|
87
|
-
type: "object",
|
|
88
|
-
properties: {
|
|
89
|
-
query: {
|
|
90
|
-
type: "string",
|
|
91
|
-
description: "Natural language or keyword search (all words must appear in name, tags, or description)",
|
|
92
|
-
},
|
|
93
|
-
provider: {
|
|
94
|
-
type: "string",
|
|
95
|
-
description: "Restrict search to tools from this provider name (e.g. 'github')",
|
|
96
|
-
},
|
|
97
|
-
limit: {
|
|
98
|
-
type: "number",
|
|
99
|
-
description: "Maximum number of results to return (default 10)",
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
required: ["query"],
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
name: "tool_info",
|
|
107
|
-
description: "Get the full schema and metadata for a specific tool by name. Use this after list_tools or search_tools to retrieve the complete input schema before calling the tool.",
|
|
108
|
-
inputSchema: {
|
|
109
|
-
type: "object",
|
|
110
|
-
properties: {
|
|
111
|
-
tool_name: {
|
|
112
|
-
type: "string",
|
|
113
|
-
description: "The MCP tool name (e.g. 'github__repos_list')",
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
required: ["tool_name"],
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
name: "call_tool",
|
|
121
|
-
description: "Execute any registered tool by name with the provided arguments. Use tool_info first to get the correct argument schema.",
|
|
122
|
-
inputSchema: {
|
|
123
|
-
type: "object",
|
|
124
|
-
properties: {
|
|
125
|
-
tool_name: {
|
|
126
|
-
type: "string",
|
|
127
|
-
description: "The MCP tool name to execute (e.g. 'github__repos_list')",
|
|
128
|
-
},
|
|
129
|
-
arguments: {
|
|
130
|
-
type: "object",
|
|
131
|
-
description: "Arguments to pass to the tool",
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
required: ["tool_name", "arguments"],
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
],
|
|
138
|
-
}));
|
|
201
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: META_TOOLS }));
|
|
139
202
|
// tools/call — dispatch to the 4 meta-tools only
|
|
140
203
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
141
204
|
const toolName = request.params.name;
|
|
142
205
|
const args = (request.params.arguments ?? {});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
: tools;
|
|
152
|
-
let result;
|
|
153
|
-
if (groupBy === "provider" || groupBy === "tag") {
|
|
154
|
-
result = groupTools(filtered, groupBy);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
result = filtered.map((t) => t.mcpName);
|
|
158
|
-
}
|
|
159
|
-
return {
|
|
160
|
-
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
// search_tools meta-tool: keyword search across tool names and descriptions
|
|
164
|
-
if (toolName === "search_tools") {
|
|
165
|
-
const query = typeof args["query"] === "string" ? args["query"] : "";
|
|
166
|
-
const providerFilter = typeof args["provider"] === "string" ? args["provider"] : undefined;
|
|
167
|
-
const limit = typeof args["limit"] === "number" && args["limit"] > 0 ? Math.floor(args["limit"]) : 10;
|
|
168
|
-
const results = searchTools(tools, query, providerFilter, limit);
|
|
169
|
-
return {
|
|
170
|
-
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
// tool_info meta-tool: return full schema and metadata for a specific tool
|
|
174
|
-
if (toolName === "tool_info") {
|
|
175
|
-
const requestedName = typeof args["tool_name"] === "string" ? args["tool_name"] : "";
|
|
176
|
-
const tool = toolMap.get(requestedName);
|
|
177
|
-
if (!tool) {
|
|
178
|
-
return {
|
|
179
|
-
isError: true,
|
|
180
|
-
content: [{ type: "text", text: `Unknown tool: ${requestedName}` }],
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
const info = {
|
|
184
|
-
name: tool.mcpName,
|
|
185
|
-
description: tool.description,
|
|
186
|
-
provider: tool.providerName,
|
|
187
|
-
inputSchema: normalizeInputSchema(tool.inputSchema),
|
|
188
|
-
};
|
|
189
|
-
return {
|
|
190
|
-
content: [{ type: "text", text: JSON.stringify(info, null, 2) }],
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
// call_tool meta-tool: execute a registered tool by name
|
|
194
|
-
if (toolName === "call_tool") {
|
|
195
|
-
const requestedName = typeof args["tool_name"] === "string" ? args["tool_name"] : "";
|
|
196
|
-
const toolArgs = typeof args["arguments"] === "object" && args["arguments"] !== null
|
|
197
|
-
? args["arguments"]
|
|
198
|
-
: {};
|
|
199
|
-
const tool = toolMap.get(requestedName);
|
|
200
|
-
if (!tool) {
|
|
201
|
-
return {
|
|
202
|
-
isError: true,
|
|
203
|
-
content: [{ type: "text", text: `Unknown tool: ${requestedName}` }],
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
try {
|
|
207
|
-
const result = await executeTool(tool, toolArgs);
|
|
208
|
-
const text = typeof result === "string" ? result : JSON.stringify(result, null, 2);
|
|
209
|
-
return { content: [{ type: "text", text }] };
|
|
210
|
-
}
|
|
211
|
-
catch (err) {
|
|
212
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
213
|
-
return {
|
|
214
|
-
isError: true,
|
|
215
|
-
content: [{ type: "text", text: `Error calling ${requestedName}: ${message}` }],
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
}
|
|
206
|
+
if (toolName === "list_tools")
|
|
207
|
+
return handleListTools(tools, args);
|
|
208
|
+
if (toolName === "search_tools")
|
|
209
|
+
return handleSearchTools(tools, args);
|
|
210
|
+
if (toolName === "tool_info")
|
|
211
|
+
return handleToolInfo(toolMap, args);
|
|
212
|
+
if (toolName === "call_tool")
|
|
213
|
+
return handleCallTool(toolMap, args);
|
|
219
214
|
return {
|
|
220
215
|
isError: true,
|
|
221
216
|
content: [
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EACL,WAAW,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEtD,8EAA8E;AAC9E,uBAAuB;AACvB,8EAA8E;AAE9E;;GAEG;AACH,SAAS,oBAAoB,CAAC,MAA+B;IAK3D,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"m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HANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utdk/mcp",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.6750ba0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Unified MCP server with dynamic tool loading from @utdk/* providers",
|
|
6
6
|
"keywords": [
|
|
@@ -17,27 +17,27 @@
|
|
|
17
17
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
18
18
|
"@utcp/http": "^1.1.1",
|
|
19
19
|
"@utcp/sdk": "^1.1.0",
|
|
20
|
-
"@utdk/common": "0.1.0-dev.
|
|
20
|
+
"@utdk/common": "0.1.0-dev.6750ba0"
|
|
21
21
|
},
|
|
22
22
|
"optionalDependencies": {
|
|
23
|
-
"@utdk/
|
|
24
|
-
"@utdk/
|
|
25
|
-
"@utdk/figma": "0.37.0-20260408.5-dev.
|
|
26
|
-
"@utdk/
|
|
27
|
-
"@utdk/
|
|
28
|
-
"@utdk/
|
|
29
|
-
"@utdk/
|
|
30
|
-
"@utdk/
|
|
31
|
-
"@utdk/
|
|
32
|
-
"@utdk/
|
|
33
|
-
"@utdk/
|
|
34
|
-
"@utdk/
|
|
35
|
-
"@utdk/
|
|
36
|
-
"@utdk/
|
|
37
|
-
"@utdk/
|
|
38
|
-
"@utdk/
|
|
39
|
-
"@utdk/
|
|
40
|
-
"@utdk/zendesk": "2.0.0-20260530.2-dev.
|
|
23
|
+
"@utdk/airtable": "0.1.0-20260530.2-dev.6750ba0",
|
|
24
|
+
"@utdk/datadog": "1.0.0-20260407.1-dev.6750ba0",
|
|
25
|
+
"@utdk/figma": "0.37.0-20260408.5-dev.6750ba0",
|
|
26
|
+
"@utdk/google": "0.0.1-20260407.8-dev.6750ba0",
|
|
27
|
+
"@utdk/github": "1.1.4-20260407.6-dev.6750ba0",
|
|
28
|
+
"@utdk/intercom": "2.15.0-20260530.1-dev.6750ba0",
|
|
29
|
+
"@utdk/hubspot": "3.0.0-20260530.2-dev.6750ba0",
|
|
30
|
+
"@utdk/jira": "1001.0.0-SNAPSHOT-500abd49de29b046db51cf0460caa503167075c0-20260530.2-dev.6750ba0",
|
|
31
|
+
"@utdk/linear": "1.0.0-20260530.1-dev.6750ba0",
|
|
32
|
+
"@utdk/notion": "1.0.0-20260530.1-dev.6750ba0",
|
|
33
|
+
"@utdk/salesforce": "58.0.0-20260530.1-dev.6750ba0",
|
|
34
|
+
"@utdk/openai": "2.3.0-20260407.1-dev.6750ba0",
|
|
35
|
+
"@utdk/sendgrid": "1.0.0-20260530.1-dev.6750ba0",
|
|
36
|
+
"@utdk/spotify": "1.0.0-20260407.6-dev.6750ba0",
|
|
37
|
+
"@utdk/stripe": "0.0.1-20260530.2-dev.6750ba0",
|
|
38
|
+
"@utdk/twilio": "1.0.0-20260530.2-dev.6750ba0",
|
|
39
|
+
"@utdk/slack": "1.7.0-20260530.1-dev.6750ba0",
|
|
40
|
+
"@utdk/zendesk": "2.0.0-20260530.2-dev.6750ba0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^25.5.0",
|
package/src/server.ts
CHANGED
|
@@ -46,16 +46,6 @@ function normalizeInputSchema(schema: Record<string, unknown>): {
|
|
|
46
46
|
properties?: Record<string, object>;
|
|
47
47
|
required?: string[];
|
|
48
48
|
} {
|
|
49
|
-
if (schema["type"] === "object") {
|
|
50
|
-
return {
|
|
51
|
-
type: "object",
|
|
52
|
-
...(schema["properties"]
|
|
53
|
-
? { properties: schema["properties"] as Record<string, object> }
|
|
54
|
-
: {}),
|
|
55
|
-
...(schema["required"] ? { required: schema["required"] as string[] } : {}),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
49
|
return {
|
|
60
50
|
type: "object",
|
|
61
51
|
...(schema["properties"]
|
|
@@ -65,7 +55,174 @@ function normalizeInputSchema(schema: Record<string, unknown>): {
|
|
|
65
55
|
};
|
|
66
56
|
}
|
|
67
57
|
|
|
68
|
-
//
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// Meta-tool definitions (served by tools/list)
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
const META_TOOLS = [
|
|
63
|
+
{
|
|
64
|
+
name: "list_tools",
|
|
65
|
+
description:
|
|
66
|
+
"List available tool names without full schemas. Pass an optional provider to filter results, or group_by to organize by category.",
|
|
67
|
+
inputSchema: {
|
|
68
|
+
type: "object" as const,
|
|
69
|
+
properties: {
|
|
70
|
+
provider: {
|
|
71
|
+
type: "string",
|
|
72
|
+
description: "Filter results to tools from this provider name (e.g. 'github')",
|
|
73
|
+
},
|
|
74
|
+
group_by: {
|
|
75
|
+
type: "string",
|
|
76
|
+
enum: ["provider", "tag"],
|
|
77
|
+
description:
|
|
78
|
+
"Group results by 'provider' or by OpenAPI 'tag'. When omitted, returns a flat list of names.",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "search_tools",
|
|
85
|
+
description:
|
|
86
|
+
"Find tools by keyword. Searches tool names, OpenAPI tags, and descriptions using TF-IDF relevance ranking so the LLM can locate relevant tools without browsing the full catalog.",
|
|
87
|
+
inputSchema: {
|
|
88
|
+
type: "object" as const,
|
|
89
|
+
properties: {
|
|
90
|
+
query: {
|
|
91
|
+
type: "string",
|
|
92
|
+
description: "Natural language or keyword search (all words must appear in name, tags, or description)",
|
|
93
|
+
},
|
|
94
|
+
provider: {
|
|
95
|
+
type: "string",
|
|
96
|
+
description: "Restrict search to tools from this provider name (e.g. 'github')",
|
|
97
|
+
},
|
|
98
|
+
limit: {
|
|
99
|
+
type: "number",
|
|
100
|
+
description: "Maximum number of results to return (default 10)",
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
required: ["query"],
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "tool_info",
|
|
108
|
+
description:
|
|
109
|
+
"Get the full schema and metadata for a specific tool by name. Use this after list_tools or search_tools to retrieve the complete input schema before calling the tool.",
|
|
110
|
+
inputSchema: {
|
|
111
|
+
type: "object" as const,
|
|
112
|
+
properties: {
|
|
113
|
+
tool_name: {
|
|
114
|
+
type: "string",
|
|
115
|
+
description: "The MCP tool name (e.g. 'github__repos_list')",
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
required: ["tool_name"],
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "call_tool",
|
|
123
|
+
description:
|
|
124
|
+
"Execute any registered tool by name with the provided arguments. Use tool_info first to get the correct argument schema.",
|
|
125
|
+
inputSchema: {
|
|
126
|
+
type: "object" as const,
|
|
127
|
+
properties: {
|
|
128
|
+
tool_name: {
|
|
129
|
+
type: "string",
|
|
130
|
+
description: "The MCP tool name to execute (e.g. 'github__repos_list')",
|
|
131
|
+
},
|
|
132
|
+
arguments: {
|
|
133
|
+
type: "object",
|
|
134
|
+
description: "Arguments to pass to the tool",
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
required: ["tool_name", "arguments"],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
// Meta-tool call handlers
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
|
|
146
|
+
function handleListTools(tools: ProviderTool[], args: Record<string, unknown>) {
|
|
147
|
+
const providerFilter =
|
|
148
|
+
typeof args["provider"] === "string" ? args["provider"] : undefined;
|
|
149
|
+
const groupBy =
|
|
150
|
+
args["group_by"] === "provider" || args["group_by"] === "tag"
|
|
151
|
+
? (args["group_by"] as "provider" | "tag")
|
|
152
|
+
: undefined;
|
|
153
|
+
const filtered = providerFilter
|
|
154
|
+
? tools.filter((t) => t.providerName === providerFilter)
|
|
155
|
+
: tools;
|
|
156
|
+
const result =
|
|
157
|
+
groupBy === "provider" || groupBy === "tag"
|
|
158
|
+
? groupTools(filtered, groupBy)
|
|
159
|
+
: filtered.map((t) => t.mcpName);
|
|
160
|
+
return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function handleSearchTools(tools: ProviderTool[], args: Record<string, unknown>) {
|
|
164
|
+
const query = typeof args["query"] === "string" ? args["query"] : "";
|
|
165
|
+
const providerFilter =
|
|
166
|
+
typeof args["provider"] === "string" ? args["provider"] : undefined;
|
|
167
|
+
const limit =
|
|
168
|
+
typeof args["limit"] === "number" && args["limit"] > 0 ? Math.floor(args["limit"]) : 10;
|
|
169
|
+
const results = searchTools(tools, query, providerFilter, limit);
|
|
170
|
+
return { content: [{ type: "text" as const, text: JSON.stringify(results, null, 2) }] };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function handleToolInfo(toolMap: Map<string, ProviderTool>, args: Record<string, unknown>) {
|
|
174
|
+
const requestedName = typeof args["tool_name"] === "string" ? args["tool_name"] : "";
|
|
175
|
+
const tool = toolMap.get(requestedName);
|
|
176
|
+
if (!tool) {
|
|
177
|
+
return {
|
|
178
|
+
isError: true,
|
|
179
|
+
content: [{ type: "text" as const, text: `Unknown tool: ${requestedName}` }],
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
type: "text" as const,
|
|
186
|
+
text: JSON.stringify(
|
|
187
|
+
{
|
|
188
|
+
name: tool.mcpName,
|
|
189
|
+
description: tool.description,
|
|
190
|
+
provider: tool.providerName,
|
|
191
|
+
inputSchema: normalizeInputSchema(tool.inputSchema),
|
|
192
|
+
},
|
|
193
|
+
null,
|
|
194
|
+
2,
|
|
195
|
+
),
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function handleCallTool(toolMap: Map<string, ProviderTool>, args: Record<string, unknown>) {
|
|
202
|
+
const requestedName = typeof args["tool_name"] === "string" ? args["tool_name"] : "";
|
|
203
|
+
const toolArgs =
|
|
204
|
+
typeof args["arguments"] === "object" && args["arguments"] !== null
|
|
205
|
+
? (args["arguments"] as Record<string, unknown>)
|
|
206
|
+
: {};
|
|
207
|
+
const tool = toolMap.get(requestedName);
|
|
208
|
+
if (!tool) {
|
|
209
|
+
return {
|
|
210
|
+
isError: true,
|
|
211
|
+
content: [{ type: "text" as const, text: `Unknown tool: ${requestedName}` }],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
const result = await executeTool(tool, toolArgs);
|
|
216
|
+
const text = typeof result === "string" ? result : JSON.stringify(result, null, 2);
|
|
217
|
+
return { content: [{ type: "text" as const, text }] };
|
|
218
|
+
} catch (err) {
|
|
219
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
220
|
+
return {
|
|
221
|
+
isError: true,
|
|
222
|
+
content: [{ type: "text" as const, text: `Error calling ${requestedName}: ${message}` }],
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
69
226
|
|
|
70
227
|
// ---------------------------------------------------------------------------
|
|
71
228
|
// MCP Server factory
|
|
@@ -86,181 +243,17 @@ function createServer(tools: ProviderTool[]): Server {
|
|
|
86
243
|
const toolMap = new Map<string, ProviderTool>(tools.map((t) => [t.mcpName, t]));
|
|
87
244
|
|
|
88
245
|
// tools/list — return exactly the 4 meta-tools (no direct provider tool exposure)
|
|
89
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
90
|
-
tools: [
|
|
91
|
-
{
|
|
92
|
-
name: "list_tools",
|
|
93
|
-
description:
|
|
94
|
-
"List available tool names without full schemas. Pass an optional provider to filter results, or group_by to organize by category.",
|
|
95
|
-
inputSchema: {
|
|
96
|
-
type: "object" as const,
|
|
97
|
-
properties: {
|
|
98
|
-
provider: {
|
|
99
|
-
type: "string",
|
|
100
|
-
description: "Filter results to tools from this provider name (e.g. 'github')",
|
|
101
|
-
},
|
|
102
|
-
group_by: {
|
|
103
|
-
type: "string",
|
|
104
|
-
enum: ["provider", "tag"],
|
|
105
|
-
description:
|
|
106
|
-
"Group results by 'provider' or by OpenAPI 'tag'. When omitted, returns a flat list of names.",
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: "search_tools",
|
|
113
|
-
description:
|
|
114
|
-
"Find tools by keyword. Searches tool names, OpenAPI tags, and descriptions using TF-IDF relevance ranking so the LLM can locate relevant tools without browsing the full catalog.",
|
|
115
|
-
inputSchema: {
|
|
116
|
-
type: "object" as const,
|
|
117
|
-
properties: {
|
|
118
|
-
query: {
|
|
119
|
-
type: "string",
|
|
120
|
-
description: "Natural language or keyword search (all words must appear in name, tags, or description)",
|
|
121
|
-
},
|
|
122
|
-
provider: {
|
|
123
|
-
type: "string",
|
|
124
|
-
description: "Restrict search to tools from this provider name (e.g. 'github')",
|
|
125
|
-
},
|
|
126
|
-
limit: {
|
|
127
|
-
type: "number",
|
|
128
|
-
description: "Maximum number of results to return (default 10)",
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
required: ["query"],
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
name: "tool_info",
|
|
136
|
-
description:
|
|
137
|
-
"Get the full schema and metadata for a specific tool by name. Use this after list_tools or search_tools to retrieve the complete input schema before calling the tool.",
|
|
138
|
-
inputSchema: {
|
|
139
|
-
type: "object" as const,
|
|
140
|
-
properties: {
|
|
141
|
-
tool_name: {
|
|
142
|
-
type: "string",
|
|
143
|
-
description: "The MCP tool name (e.g. 'github__repos_list')",
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
required: ["tool_name"],
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
name: "call_tool",
|
|
151
|
-
description:
|
|
152
|
-
"Execute any registered tool by name with the provided arguments. Use tool_info first to get the correct argument schema.",
|
|
153
|
-
inputSchema: {
|
|
154
|
-
type: "object" as const,
|
|
155
|
-
properties: {
|
|
156
|
-
tool_name: {
|
|
157
|
-
type: "string",
|
|
158
|
-
description: "The MCP tool name to execute (e.g. 'github__repos_list')",
|
|
159
|
-
},
|
|
160
|
-
arguments: {
|
|
161
|
-
type: "object",
|
|
162
|
-
description: "Arguments to pass to the tool",
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
required: ["tool_name", "arguments"],
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
}));
|
|
246
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: META_TOOLS }));
|
|
170
247
|
|
|
171
248
|
// tools/call — dispatch to the 4 meta-tools only
|
|
172
249
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
173
250
|
const toolName = request.params.name;
|
|
174
251
|
const args = (request.params.arguments ?? {}) as Record<string, unknown>;
|
|
175
252
|
|
|
176
|
-
|
|
177
|
-
if (toolName === "
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const groupBy =
|
|
181
|
-
args["group_by"] === "provider" || args["group_by"] === "tag"
|
|
182
|
-
? (args["group_by"] as "provider" | "tag")
|
|
183
|
-
: undefined;
|
|
184
|
-
|
|
185
|
-
const filtered = providerFilter
|
|
186
|
-
? tools.filter((t) => t.providerName === providerFilter)
|
|
187
|
-
: tools;
|
|
188
|
-
|
|
189
|
-
let result: unknown;
|
|
190
|
-
|
|
191
|
-
if (groupBy === "provider" || groupBy === "tag") {
|
|
192
|
-
result = groupTools(filtered, groupBy);
|
|
193
|
-
} else {
|
|
194
|
-
result = filtered.map((t) => t.mcpName);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return {
|
|
198
|
-
content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }],
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// search_tools meta-tool: keyword search across tool names and descriptions
|
|
203
|
-
if (toolName === "search_tools") {
|
|
204
|
-
const query = typeof args["query"] === "string" ? args["query"] : "";
|
|
205
|
-
const providerFilter =
|
|
206
|
-
typeof args["provider"] === "string" ? args["provider"] : undefined;
|
|
207
|
-
const limit =
|
|
208
|
-
typeof args["limit"] === "number" && args["limit"] > 0 ? Math.floor(args["limit"]) : 10;
|
|
209
|
-
const results = searchTools(tools, query, providerFilter, limit);
|
|
210
|
-
return {
|
|
211
|
-
content: [{ type: "text" as const, text: JSON.stringify(results, null, 2) }],
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// tool_info meta-tool: return full schema and metadata for a specific tool
|
|
216
|
-
if (toolName === "tool_info") {
|
|
217
|
-
const requestedName = typeof args["tool_name"] === "string" ? args["tool_name"] : "";
|
|
218
|
-
const tool = toolMap.get(requestedName);
|
|
219
|
-
if (!tool) {
|
|
220
|
-
return {
|
|
221
|
-
isError: true,
|
|
222
|
-
content: [{ type: "text" as const, text: `Unknown tool: ${requestedName}` }],
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
const info = {
|
|
226
|
-
name: tool.mcpName,
|
|
227
|
-
description: tool.description,
|
|
228
|
-
provider: tool.providerName,
|
|
229
|
-
inputSchema: normalizeInputSchema(tool.inputSchema),
|
|
230
|
-
};
|
|
231
|
-
return {
|
|
232
|
-
content: [{ type: "text" as const, text: JSON.stringify(info, null, 2) }],
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// call_tool meta-tool: execute a registered tool by name
|
|
237
|
-
if (toolName === "call_tool") {
|
|
238
|
-
const requestedName = typeof args["tool_name"] === "string" ? args["tool_name"] : "";
|
|
239
|
-
const toolArgs =
|
|
240
|
-
typeof args["arguments"] === "object" && args["arguments"] !== null
|
|
241
|
-
? (args["arguments"] as Record<string, unknown>)
|
|
242
|
-
: {};
|
|
243
|
-
|
|
244
|
-
const tool = toolMap.get(requestedName);
|
|
245
|
-
if (!tool) {
|
|
246
|
-
return {
|
|
247
|
-
isError: true,
|
|
248
|
-
content: [{ type: "text" as const, text: `Unknown tool: ${requestedName}` }],
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
try {
|
|
253
|
-
const result = await executeTool(tool, toolArgs);
|
|
254
|
-
const text = typeof result === "string" ? result : JSON.stringify(result, null, 2);
|
|
255
|
-
return { content: [{ type: "text" as const, text }] };
|
|
256
|
-
} catch (err) {
|
|
257
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
258
|
-
return {
|
|
259
|
-
isError: true,
|
|
260
|
-
content: [{ type: "text" as const, text: `Error calling ${requestedName}: ${message}` }],
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
}
|
|
253
|
+
if (toolName === "list_tools") return handleListTools(tools, args);
|
|
254
|
+
if (toolName === "search_tools") return handleSearchTools(tools, args);
|
|
255
|
+
if (toolName === "tool_info") return handleToolInfo(toolMap, args);
|
|
256
|
+
if (toolName === "call_tool") return handleCallTool(toolMap, args);
|
|
264
257
|
|
|
265
258
|
return {
|
|
266
259
|
isError: true,
|