@utdk/mcp 0.1.0-dev.646adf4 → 0.1.0-dev.8f50777
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/loader.js.map +1 -1
- package/dist/server.js +158 -163
- package/dist/server.js.map +1 -1
- package/package.json +20 -20
- package/src/loader.ts +1 -3
- package/src/server.ts +176 -184
- package/vitest.config.ts +5 -6
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAgD9C;;GAEG;AACH,SAAS,iBAAiB,CAAC,aAAqB;IAC9C,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;IAC1D,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,QAAgB;IACrC,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;AACvE,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,mBAAmB,CAAC,YAAoB;IAIrD,MAAM,WAAW,GAAG,SAAS,YAAY,EA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a,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAEnC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,cAAc;YACvB,IAAI;SACL,CAAC,CAAC;QAEH,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAEvD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CACb,qBAAqB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAClG,CAAC;QACJ,CAAC;QAED,iBAAiB;QACjB,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACvD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;QAC/D,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACjC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzB,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/dist/server.js
CHANGED
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* Hot-reload:
|
|
18
18
|
* Send SIGHUP to reload provider list from the current UTDK_PROVIDERS env value.
|
|
19
19
|
*/
|
|
20
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
21
20
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
22
21
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
22
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
23
23
|
import { executeTool, initTelemetry, loadProviders, parseProviderNames, } from "./loader.js";
|
|
24
24
|
import { searchTools, groupTools } from "./search.js";
|
|
25
25
|
// ---------------------------------------------------------------------------
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,WAAW,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,E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E,4EAA4E;YAC5E,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;YAChC,wEAAwE;YACxE,yCAAyC;YACzC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACtC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,8CAA8C,GAAG,IAAI,CAAC,CAAC;YAC9E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,GAAG,IAAI,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;QACzB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACzE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAAC;IACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utdk/mcp",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.8f50777",
|
|
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.8f50777"
|
|
21
21
|
},
|
|
22
22
|
"optionalDependencies": {
|
|
23
|
-
"@utdk/
|
|
24
|
-
"@utdk/
|
|
25
|
-
"@utdk/
|
|
26
|
-
"@utdk/
|
|
27
|
-
"@utdk/
|
|
28
|
-
"@utdk/hubspot": "3.0.0-20260530.2-dev.
|
|
29
|
-
"@utdk/
|
|
30
|
-
"@utdk/
|
|
31
|
-
"@utdk/
|
|
32
|
-
"@utdk/
|
|
33
|
-
"@utdk/
|
|
34
|
-
"@utdk/
|
|
35
|
-
"@utdk/
|
|
36
|
-
"@utdk/sendgrid": "1.0.0-20260530.1-dev.
|
|
37
|
-
"@utdk/
|
|
38
|
-
"@utdk/
|
|
39
|
-
"@utdk/
|
|
40
|
-
"@utdk/
|
|
23
|
+
"@utdk/airtable": "0.1.0-20260530.2-dev.8f50777",
|
|
24
|
+
"@utdk/datadog": "1.0.0-20260407.1-dev.8f50777",
|
|
25
|
+
"@utdk/github": "1.1.4-20260407.6-dev.8f50777",
|
|
26
|
+
"@utdk/google": "0.0.1-20260407.8-dev.8f50777",
|
|
27
|
+
"@utdk/figma": "0.37.0-20260408.5-dev.8f50777",
|
|
28
|
+
"@utdk/hubspot": "3.0.0-20260530.2-dev.8f50777",
|
|
29
|
+
"@utdk/jira": "1001.0.0-SNAPSHOT-500abd49de29b046db51cf0460caa503167075c0-20260530.2-dev.8f50777",
|
|
30
|
+
"@utdk/intercom": "2.15.0-20260530.1-dev.8f50777",
|
|
31
|
+
"@utdk/linear": "1.0.0-20260530.1-dev.8f50777",
|
|
32
|
+
"@utdk/notion": "1.0.0-20260530.1-dev.8f50777",
|
|
33
|
+
"@utdk/openai": "2.3.0-20260407.1-dev.8f50777",
|
|
34
|
+
"@utdk/slack": "1.7.0-20260530.1-dev.8f50777",
|
|
35
|
+
"@utdk/stripe": "0.0.1-20260530.2-dev.8f50777",
|
|
36
|
+
"@utdk/sendgrid": "1.0.0-20260530.1-dev.8f50777",
|
|
37
|
+
"@utdk/twilio": "1.0.0-20260530.2-dev.8f50777",
|
|
38
|
+
"@utdk/zendesk": "2.0.0-20260530.2-dev.8f50777",
|
|
39
|
+
"@utdk/salesforce": "58.0.0-20260530.1-dev.8f50777",
|
|
40
|
+
"@utdk/spotify": "1.0.0-20260407.6-dev.8f50777"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^25.5.0",
|
package/src/loader.ts
CHANGED
|
@@ -6,12 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { OpenApiConverter } from "@utcp/http";
|
|
9
|
-
import type { Tool } from "@utcp/sdk";
|
|
10
|
-
import type { AuthProvider } from "@utdk/common";
|
|
11
9
|
import { withSpan, configureTelemetry } from "@utdk/common";
|
|
12
|
-
|
|
13
10
|
import { buildAuthProvider } from "./auth.js";
|
|
14
11
|
import type { UtdkAuthConfig } from "./auth.js";
|
|
12
|
+
import type { AuthProvider } from "@utdk/common";
|
|
15
13
|
|
|
16
14
|
export interface ProviderTool {
|
|
17
15
|
/** MCP tool name (e.g. "github__repos_list") */
|
package/src/server.ts
CHANGED
|
@@ -18,21 +18,20 @@
|
|
|
18
18
|
* Send SIGHUP to reload provider list from the current UTDK_PROVIDERS env value.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
22
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
21
23
|
import {
|
|
22
24
|
CallToolRequestSchema,
|
|
23
25
|
ListToolsRequestSchema,
|
|
24
26
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
25
|
-
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
26
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
27
|
-
|
|
28
27
|
import {
|
|
29
28
|
executeTool,
|
|
30
29
|
initTelemetry,
|
|
31
30
|
loadProviders,
|
|
32
31
|
parseProviderNames,
|
|
33
32
|
} from "./loader.js";
|
|
34
|
-
import type { ProviderTool } from "./loader.js";
|
|
35
33
|
import { searchTools, groupTools } from "./search.js";
|
|
34
|
+
import type { ProviderTool } from "./loader.js";
|
|
36
35
|
|
|
37
36
|
// ---------------------------------------------------------------------------
|
|
38
37
|
// Schema normalization
|
|
@@ -46,16 +45,6 @@ function normalizeInputSchema(schema: Record<string, unknown>): {
|
|
|
46
45
|
properties?: Record<string, object>;
|
|
47
46
|
required?: string[];
|
|
48
47
|
} {
|
|
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
48
|
return {
|
|
60
49
|
type: "object",
|
|
61
50
|
...(schema["properties"]
|
|
@@ -65,7 +54,174 @@ function normalizeInputSchema(schema: Record<string, unknown>): {
|
|
|
65
54
|
};
|
|
66
55
|
}
|
|
67
56
|
|
|
68
|
-
//
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Meta-tool definitions (served by tools/list)
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
const META_TOOLS = [
|
|
62
|
+
{
|
|
63
|
+
name: "list_tools",
|
|
64
|
+
description:
|
|
65
|
+
"List available tool names without full schemas. Pass an optional provider to filter results, or group_by to organize by category.",
|
|
66
|
+
inputSchema: {
|
|
67
|
+
type: "object" as const,
|
|
68
|
+
properties: {
|
|
69
|
+
provider: {
|
|
70
|
+
type: "string",
|
|
71
|
+
description: "Filter results to tools from this provider name (e.g. 'github')",
|
|
72
|
+
},
|
|
73
|
+
group_by: {
|
|
74
|
+
type: "string",
|
|
75
|
+
enum: ["provider", "tag"],
|
|
76
|
+
description:
|
|
77
|
+
"Group results by 'provider' or by OpenAPI 'tag'. When omitted, returns a flat list of names.",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "search_tools",
|
|
84
|
+
description:
|
|
85
|
+
"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" as const,
|
|
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:
|
|
108
|
+
"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.",
|
|
109
|
+
inputSchema: {
|
|
110
|
+
type: "object" as const,
|
|
111
|
+
properties: {
|
|
112
|
+
tool_name: {
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "The MCP tool name (e.g. 'github__repos_list')",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
required: ["tool_name"],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "call_tool",
|
|
122
|
+
description:
|
|
123
|
+
"Execute any registered tool by name with the provided arguments. Use tool_info first to get the correct argument schema.",
|
|
124
|
+
inputSchema: {
|
|
125
|
+
type: "object" as const,
|
|
126
|
+
properties: {
|
|
127
|
+
tool_name: {
|
|
128
|
+
type: "string",
|
|
129
|
+
description: "The MCP tool name to execute (e.g. 'github__repos_list')",
|
|
130
|
+
},
|
|
131
|
+
arguments: {
|
|
132
|
+
type: "object",
|
|
133
|
+
description: "Arguments to pass to the tool",
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
required: ["tool_name", "arguments"],
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
// Meta-tool call handlers
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
|
|
145
|
+
function handleListTools(tools: ProviderTool[], args: Record<string, unknown>) {
|
|
146
|
+
const providerFilter =
|
|
147
|
+
typeof args["provider"] === "string" ? args["provider"] : undefined;
|
|
148
|
+
const groupBy =
|
|
149
|
+
args["group_by"] === "provider" || args["group_by"] === "tag"
|
|
150
|
+
? (args["group_by"] as "provider" | "tag")
|
|
151
|
+
: undefined;
|
|
152
|
+
const filtered = providerFilter
|
|
153
|
+
? tools.filter((t) => t.providerName === providerFilter)
|
|
154
|
+
: tools;
|
|
155
|
+
const result =
|
|
156
|
+
groupBy === "provider" || groupBy === "tag"
|
|
157
|
+
? groupTools(filtered, groupBy)
|
|
158
|
+
: filtered.map((t) => t.mcpName);
|
|
159
|
+
return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function handleSearchTools(tools: ProviderTool[], args: Record<string, unknown>) {
|
|
163
|
+
const query = typeof args["query"] === "string" ? args["query"] : "";
|
|
164
|
+
const providerFilter =
|
|
165
|
+
typeof args["provider"] === "string" ? args["provider"] : undefined;
|
|
166
|
+
const limit =
|
|
167
|
+
typeof args["limit"] === "number" && args["limit"] > 0 ? Math.floor(args["limit"]) : 10;
|
|
168
|
+
const results = searchTools(tools, query, providerFilter, limit);
|
|
169
|
+
return { content: [{ type: "text" as const, text: JSON.stringify(results, null, 2) }] };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function handleToolInfo(toolMap: Map<string, ProviderTool>, args: Record<string, unknown>) {
|
|
173
|
+
const requestedName = typeof args["tool_name"] === "string" ? args["tool_name"] : "";
|
|
174
|
+
const tool = toolMap.get(requestedName);
|
|
175
|
+
if (!tool) {
|
|
176
|
+
return {
|
|
177
|
+
isError: true,
|
|
178
|
+
content: [{ type: "text" as const, text: `Unknown tool: ${requestedName}` }],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
content: [
|
|
183
|
+
{
|
|
184
|
+
type: "text" as const,
|
|
185
|
+
text: JSON.stringify(
|
|
186
|
+
{
|
|
187
|
+
name: tool.mcpName,
|
|
188
|
+
description: tool.description,
|
|
189
|
+
provider: tool.providerName,
|
|
190
|
+
inputSchema: normalizeInputSchema(tool.inputSchema),
|
|
191
|
+
},
|
|
192
|
+
null,
|
|
193
|
+
2,
|
|
194
|
+
),
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function handleCallTool(toolMap: Map<string, ProviderTool>, args: Record<string, unknown>) {
|
|
201
|
+
const requestedName = typeof args["tool_name"] === "string" ? args["tool_name"] : "";
|
|
202
|
+
const toolArgs =
|
|
203
|
+
typeof args["arguments"] === "object" && args["arguments"] !== null
|
|
204
|
+
? (args["arguments"] as Record<string, unknown>)
|
|
205
|
+
: {};
|
|
206
|
+
const tool = toolMap.get(requestedName);
|
|
207
|
+
if (!tool) {
|
|
208
|
+
return {
|
|
209
|
+
isError: true,
|
|
210
|
+
content: [{ type: "text" as const, text: `Unknown tool: ${requestedName}` }],
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const result = await executeTool(tool, toolArgs);
|
|
215
|
+
const text = typeof result === "string" ? result : JSON.stringify(result, null, 2);
|
|
216
|
+
return { content: [{ type: "text" as const, text }] };
|
|
217
|
+
} catch (err) {
|
|
218
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
219
|
+
return {
|
|
220
|
+
isError: true,
|
|
221
|
+
content: [{ type: "text" as const, text: `Error calling ${requestedName}: ${message}` }],
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
69
225
|
|
|
70
226
|
// ---------------------------------------------------------------------------
|
|
71
227
|
// MCP Server factory
|
|
@@ -86,181 +242,17 @@ function createServer(tools: ProviderTool[]): Server {
|
|
|
86
242
|
const toolMap = new Map<string, ProviderTool>(tools.map((t) => [t.mcpName, t]));
|
|
87
243
|
|
|
88
244
|
// 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
|
-
}));
|
|
245
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: META_TOOLS }));
|
|
170
246
|
|
|
171
247
|
// tools/call — dispatch to the 4 meta-tools only
|
|
172
248
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
173
249
|
const toolName = request.params.name;
|
|
174
250
|
const args = (request.params.arguments ?? {}) as Record<string, unknown>;
|
|
175
251
|
|
|
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
|
-
}
|
|
252
|
+
if (toolName === "list_tools") return handleListTools(tools, args);
|
|
253
|
+
if (toolName === "search_tools") return handleSearchTools(tools, args);
|
|
254
|
+
if (toolName === "tool_info") return handleToolInfo(toolMap, args);
|
|
255
|
+
if (toolName === "call_tool") return handleCallTool(toolMap, args);
|
|
264
256
|
|
|
265
257
|
return {
|
|
266
258
|
isError: true,
|
package/vitest.config.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { defineConfig } from "vitest
|
|
1
|
+
import { defineConfig } from "@aprovan/vitest-config";
|
|
2
2
|
|
|
3
|
-
export default
|
|
4
|
-
test: {
|
|
5
|
-
environment: "node",
|
|
3
|
+
export default {
|
|
4
|
+
test: defineConfig("node", {
|
|
6
5
|
include: ["src/**/*.test.ts"],
|
|
7
6
|
testTimeout: 30000,
|
|
8
|
-
},
|
|
9
|
-
}
|
|
7
|
+
}),
|
|
8
|
+
};
|