@glows777/vela-mcp 0.0.0-stage → 0.5.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/CHANGELOG.md +263 -0
- package/LICENSE +21 -0
- package/README.md +4 -2
- package/dist/config.d.ts +79 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +226 -0
- package/dist/config.js.map +1 -0
- package/dist/connection.d.ts +61 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +248 -0
- package/dist/connection.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +200 -0
- package/dist/index.js.map +1 -0
- package/dist/tools.d.ts +40 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +167 -0
- package/dist/tools.js.map +1 -0
- package/package.json +38 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in MCP extension (like pi's `extensions/mcp`): connects to MCP servers over stdio or
|
|
3
|
+
* streamable HTTP and registers their tools as `mcp__<server>__<tool>`, deferred by default so
|
|
4
|
+
* tool_search loads them on demand.
|
|
5
|
+
*
|
|
6
|
+
* Unlike pi, one set of connections serves all sessions of a Vela (a Lark bot has many concurrent
|
|
7
|
+
* sessions); they start with the first session and close when the Vela is disposed.
|
|
8
|
+
*/
|
|
9
|
+
import { parseServers, toolExposureOf, } from "./config.js";
|
|
10
|
+
import { McpConnection } from "./connection.js";
|
|
11
|
+
import { createMcpTool, createMcpToolName, namespaceName } from "./tools.js";
|
|
12
|
+
/** The first prompt waits this long for servers with direct tools (like pi). */
|
|
13
|
+
const DIRECT_WAIT_MS = 10_000;
|
|
14
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
15
|
+
/** The built-in MCP extension. Its tools are `mcp__<server>__<tool>`. */
|
|
16
|
+
export function mcp(options = {}) {
|
|
17
|
+
return function mcp(vela) {
|
|
18
|
+
const fromConfig = isRecord(vela.config.mcpServers)
|
|
19
|
+
? vela.config.mcpServers
|
|
20
|
+
: {};
|
|
21
|
+
const sources = isRecord(vela.config.sources)
|
|
22
|
+
? vela.config.sources
|
|
23
|
+
: {};
|
|
24
|
+
const { entries, errors } = parseServers(options.servers ?? fromConfig, options.servers ? {} : sources);
|
|
25
|
+
// Errors found while reading mcp.json (bad JSON, unset variables)
|
|
26
|
+
if (!options.servers && Array.isArray(vela.config.errors))
|
|
27
|
+
errors.unshift(...vela.config.errors.map(String));
|
|
28
|
+
const connections = new Map();
|
|
29
|
+
/** Server → its registered tool names */
|
|
30
|
+
const registered = new Map();
|
|
31
|
+
/** Registered MCP tool name → `<server>\0<tool>`, to detect sanitized names that collide */
|
|
32
|
+
const owners = new Map();
|
|
33
|
+
const syncTools = (connection) => {
|
|
34
|
+
const { name: server, config } = connection.entry;
|
|
35
|
+
for (const toolName of registered.get(server) ?? []) {
|
|
36
|
+
vela.unregisterTool(toolName);
|
|
37
|
+
owners.delete(toolName);
|
|
38
|
+
}
|
|
39
|
+
const names = [];
|
|
40
|
+
const namespace = {
|
|
41
|
+
name: namespaceName(server),
|
|
42
|
+
description: config.description ?? connection.instructions?.split('\n')[0],
|
|
43
|
+
...(connection.instructions
|
|
44
|
+
? { instructions: connection.instructions }
|
|
45
|
+
: {}),
|
|
46
|
+
};
|
|
47
|
+
for (const tool of connection.tools) {
|
|
48
|
+
const owner = `${server}\0${tool.name}`;
|
|
49
|
+
const name = createMcpToolName(server, tool.name, (candidate) => {
|
|
50
|
+
const existing = owners.get(candidate);
|
|
51
|
+
return existing !== undefined && existing !== owner;
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
vela.registerTool(createMcpTool({
|
|
55
|
+
server,
|
|
56
|
+
tool,
|
|
57
|
+
name,
|
|
58
|
+
exposure: toolExposureOf(config, tool.name),
|
|
59
|
+
namespace,
|
|
60
|
+
caller: connection,
|
|
61
|
+
}));
|
|
62
|
+
names.push(name);
|
|
63
|
+
owners.set(name, owner);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
vela.logger.error(`[mcp] ${server}: could not register ${tool.name}: ${error instanceof Error ? error.message : error}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
registered.set(server, names);
|
|
70
|
+
};
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
if (entry.config.enabled === false)
|
|
73
|
+
continue;
|
|
74
|
+
connections.set(entry.name, new McpConnection({
|
|
75
|
+
entry,
|
|
76
|
+
cwd: vela.cwd,
|
|
77
|
+
onTools: syncTools,
|
|
78
|
+
...(options.createTransport
|
|
79
|
+
? { createTransport: options.createTransport }
|
|
80
|
+
: {}),
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
/** Settles when every server has connected or failed (started on the first session_start). */
|
|
84
|
+
let started;
|
|
85
|
+
/** Settles when the servers that declare direct tools have connected or failed. */
|
|
86
|
+
let directReady = Promise.resolve();
|
|
87
|
+
const start = (ctx) => {
|
|
88
|
+
if (started)
|
|
89
|
+
return;
|
|
90
|
+
const attempts = [...connections.values()].map((connection) => ({
|
|
91
|
+
connection,
|
|
92
|
+
done: connection.connect().then(() => undefined, (error) => error instanceof Error ? error.message : String(error)),
|
|
93
|
+
}));
|
|
94
|
+
directReady = Promise.all(attempts
|
|
95
|
+
.filter(({ connection }) => hasDirectTools(connection.entry))
|
|
96
|
+
.map(({ done }) => done)).then(() => { });
|
|
97
|
+
const report = (problems) => {
|
|
98
|
+
if (problems.length === 0)
|
|
99
|
+
return;
|
|
100
|
+
const message = `[mcp] ${problems.join('\n[mcp] ')}\nRun /mcp for details.`;
|
|
101
|
+
if (ctx.hasUI)
|
|
102
|
+
ctx.ui.notify(message, 'error');
|
|
103
|
+
else
|
|
104
|
+
vela.logger.error(message);
|
|
105
|
+
};
|
|
106
|
+
// Report configuration errors now and failed connections once they settle (like pi)
|
|
107
|
+
report(errors);
|
|
108
|
+
started = Promise.all(attempts.map(({ done }) => done)).then((failures) => report(failures.filter((f) => f !== undefined)));
|
|
109
|
+
};
|
|
110
|
+
vela.on('session_start', (_event, ctx) => {
|
|
111
|
+
if (connections.size === 0 && errors.length === 0)
|
|
112
|
+
return;
|
|
113
|
+
start(ctx);
|
|
114
|
+
});
|
|
115
|
+
// The first prompt waits (up to 10s) only for servers with direct tools, which must be declared
|
|
116
|
+
// in its request; deferred tools are waited for by tool_search (like pi)
|
|
117
|
+
vela.on('before_agent_start', async (event) => {
|
|
118
|
+
if (!started)
|
|
119
|
+
return;
|
|
120
|
+
let timer;
|
|
121
|
+
await Promise.race([
|
|
122
|
+
directReady,
|
|
123
|
+
new Promise((resolve) => {
|
|
124
|
+
timer = setTimeout(resolve, DIRECT_WAIT_MS);
|
|
125
|
+
}),
|
|
126
|
+
]);
|
|
127
|
+
clearTimeout(timer);
|
|
128
|
+
// Servers still connecting once the wait is over are listed by name, so the model knows to
|
|
129
|
+
// search for their tools (like pi's mcp_servers section); connected servers appear in the
|
|
130
|
+
// deferred tool list
|
|
131
|
+
const pending = [...connections.values()].filter((c) => (c.state === 'connecting' || c.state === 'idle') &&
|
|
132
|
+
hasVisibleTools(c.entry));
|
|
133
|
+
if (pending.length)
|
|
134
|
+
event.sections.mcp_servers = [
|
|
135
|
+
'MCP servers still connecting (tool_search waits for them and finds their tools):',
|
|
136
|
+
...pending.map((c) => `- ${namespaceName(c.name)}${c.entry.config.description ? ` — ${c.entry.config.description}` : ''}`),
|
|
137
|
+
].join('\n');
|
|
138
|
+
});
|
|
139
|
+
vela.on('tool_call', async (event) => {
|
|
140
|
+
// tool_search waits for servers that are still connecting, so it can find their tools
|
|
141
|
+
if (event.toolName === 'tool_search' && started)
|
|
142
|
+
await started;
|
|
143
|
+
});
|
|
144
|
+
vela.registerCommand('mcp', {
|
|
145
|
+
description: 'Show MCP servers and their tools; /mcp reconnect <server> to reconnect one',
|
|
146
|
+
handler: async (args, ctx) => {
|
|
147
|
+
const [action, server] = args.split(/\s+/);
|
|
148
|
+
if (action === 'reconnect') {
|
|
149
|
+
const connection = server ? connections.get(server) : undefined;
|
|
150
|
+
if (!connection)
|
|
151
|
+
return ctx.ui.notify(`Unknown MCP server "${server ?? ''}". Servers: ${[...connections.keys()].join(', ') || 'none'}`, 'error');
|
|
152
|
+
try {
|
|
153
|
+
await connection.reconnect();
|
|
154
|
+
ctx.ui.notify(`MCP server "${connection.name}" connected (${connection.tools.length} tools)`);
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
ctx.ui.notify(error instanceof Error ? error.message : String(error), 'error');
|
|
158
|
+
}
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (action)
|
|
162
|
+
return ctx.ui.notify('Usage: /mcp [reconnect <server>]');
|
|
163
|
+
ctx.ui.notify(statusReport(entries, connections, registered, errors));
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
vela.onShutdown(async () => {
|
|
167
|
+
await Promise.all([...connections.values()].map((c) => c.close()));
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/** Whether any of the server's tools may be visible to the model (not all `hidden`). */
|
|
172
|
+
function hasVisibleTools(entry) {
|
|
173
|
+
const { config } = entry;
|
|
174
|
+
return (config.exposure !== 'hidden' ||
|
|
175
|
+
Object.values(config.toolExposure ?? {}).some((e) => e !== 'hidden'));
|
|
176
|
+
}
|
|
177
|
+
/** Whether any of the server's tools may have `direct` exposure. */
|
|
178
|
+
function hasDirectTools(entry) {
|
|
179
|
+
const { config } = entry;
|
|
180
|
+
return (config.exposure === 'direct' ||
|
|
181
|
+
Object.values(config.toolExposure ?? {}).includes('direct'));
|
|
182
|
+
}
|
|
183
|
+
function statusReport(entries, connections, registered, errors) {
|
|
184
|
+
if (entries.length === 0 && errors.length === 0)
|
|
185
|
+
return 'No MCP servers configured. Add them to ~/.vela/mcp.json or .vela/mcp.json (see docs/mcp.md).';
|
|
186
|
+
const lines = ['MCP servers:'];
|
|
187
|
+
for (const entry of entries) {
|
|
188
|
+
const connection = connections.get(entry.name);
|
|
189
|
+
const state = connection ? connection.state : 'disabled';
|
|
190
|
+
const tools = registered.get(entry.name)?.length ?? 0;
|
|
191
|
+
lines.push(`- ${entry.name}: ${state}, ${tools} tool${tools === 1 ? '' : 's'}, exposure ${entry.config.exposure ?? 'deferred'} (${entry.source})`);
|
|
192
|
+
if (connection?.error)
|
|
193
|
+
lines.push(` ${connection.error.replaceAll('\n', '\n ')}`);
|
|
194
|
+
}
|
|
195
|
+
for (const error of errors)
|
|
196
|
+
lines.push(`- error: ${error}`);
|
|
197
|
+
return lines.join('\n');
|
|
198
|
+
}
|
|
199
|
+
export { mcpConfig } from "./config.js";
|
|
200
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,EAGL,YAAY,EACZ,cAAc,GACf,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAU5E,gFAAgF;AAChF,MAAM,cAAc,GAAG,MAAM,CAAA;AAa7B,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAEtE,yEAAyE;AACzE,MAAM,UAAU,GAAG,CAAC,UAAsB,EAAE;IAC1C,OAAO,SAAS,GAAG,CAAC,IAAI;QACtB,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;YACjD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU;YACxB,CAAC,CAAC,EAAE,CAAA;QACN,MAAM,OAAO,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K,CAAC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC,CAAA;QACrD,KAAK,CAAC,IAAI,CACR,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,KAAK,KAAK,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,cAAc,KAAK,CAAC,MAAM,CAAC,QAAQ,IAAI,UAAU,KAAK,KAAK,CAAC,MAAM,GAAG,CACvI,CAAA;QACD,IAAI,UAAU,EAAE,KAAK;YACnB,KAAK,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,CAAA;IAChE,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC,CAAA;IAC3D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ToolDefinition, ToolNamespace } from '@glows777/vela-core/extension-api';
|
|
2
|
+
import { ToolExecutionResult } from '@glows777/vela-core/extension-api';
|
|
3
|
+
import type { CallToolResult, Tool as McpTool } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import type { McpExposure } from './config.ts';
|
|
5
|
+
/**
|
|
6
|
+
* `mcp__<server>__<tool>`, with everything but `[A-Za-z0-9_]` replaced by `_` (like pi and Codex),
|
|
7
|
+
* and shortened with a hash suffix when too long or when `isTaken` reports the name is used by
|
|
8
|
+
* another MCP tool (`a-b` and `a_b` map to the same name).
|
|
9
|
+
*/
|
|
10
|
+
export declare function createMcpToolName(server: string, tool: string, isTaken?: (name: string) => boolean): string;
|
|
11
|
+
/** `mcp__<server>`: the namespace of a server's tools. */
|
|
12
|
+
export declare function namespaceName(server: string): string;
|
|
13
|
+
/** Text projection of an MCP result. Images are separate; absent content falls back to structured JSON. */
|
|
14
|
+
export declare function mcpResultText(server: string, tool: string, result: CallToolResult): string;
|
|
15
|
+
/**
|
|
16
|
+
* The result for Vela: text and images for the model, and `CallToolResult` without `_meta` as
|
|
17
|
+
* the native value (kept in tool history; what codemode scripts will receive). `isError` results
|
|
18
|
+
* are error results for the model.
|
|
19
|
+
*/
|
|
20
|
+
export declare function convertMcpResult(server: string, tool: string, result: CallToolResult): ToolExecutionResult;
|
|
21
|
+
/** What a tool needs from its server's connection. */
|
|
22
|
+
export interface McpToolCaller {
|
|
23
|
+
callTool(name: string, args: Record<string, unknown>, options: {
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
onProgress?: (progress: {
|
|
26
|
+
progress: number;
|
|
27
|
+
total?: number;
|
|
28
|
+
message?: string;
|
|
29
|
+
}) => void;
|
|
30
|
+
}): Promise<CallToolResult>;
|
|
31
|
+
}
|
|
32
|
+
export declare function createMcpTool(options: {
|
|
33
|
+
server: string;
|
|
34
|
+
tool: McpTool;
|
|
35
|
+
name: string;
|
|
36
|
+
exposure: McpExposure;
|
|
37
|
+
namespace: ToolNamespace;
|
|
38
|
+
caller: McpToolCaller;
|
|
39
|
+
}): ToolDefinition;
|
|
40
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAEV,cAAc,EACd,aAAa,EACd,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,KAAK,EACV,cAAc,EACd,IAAI,IAAI,OAAO,EAChB,MAAM,oCAAoC,CAAA;AAE3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAS9C;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,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ools (like pi's `extensions/mcp/tools.ts`). Images stay as canonical image
|
|
4
|
+
* content; audio and binary resources become one-line placeholders. Long text goes through Vela's
|
|
5
|
+
* usual "save the full output, show a head and tail preview" with pi's 20KB limit.
|
|
6
|
+
*/
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
import { ToolExecutionResult } from '@glows777/vela-core/extension-api';
|
|
9
|
+
import { jsonSchema } from 'ai';
|
|
10
|
+
/** Provider tool names are limited to 64 characters of `[A-Za-z0-9_-]`. */
|
|
11
|
+
const MAX_TOOL_NAME_LENGTH = 64;
|
|
12
|
+
/** Model-facing text beyond this is saved to a file and previewed (pi cuts MCP text at 20KB). */
|
|
13
|
+
const MCP_MAX_RESULT_CHARS = 20_000;
|
|
14
|
+
/**
|
|
15
|
+
* `mcp__<server>__<tool>`, with everything but `[A-Za-z0-9_]` replaced by `_` (like pi and Codex),
|
|
16
|
+
* and shortened with a hash suffix when too long or when `isTaken` reports the name is used by
|
|
17
|
+
* another MCP tool (`a-b` and `a_b` map to the same name).
|
|
18
|
+
*/
|
|
19
|
+
export function createMcpToolName(server, tool, isTaken = () => false) {
|
|
20
|
+
const name = `mcp__${server}__${tool}`.replace(/[^A-Za-z0-9_]/g, '_');
|
|
21
|
+
if (name.length <= MAX_TOOL_NAME_LENGTH && !isTaken(name))
|
|
22
|
+
return name;
|
|
23
|
+
const hash = createHash('sha256')
|
|
24
|
+
.update(`${server}\0${tool}`)
|
|
25
|
+
.digest('hex')
|
|
26
|
+
.slice(0, 8);
|
|
27
|
+
return `${name.slice(0, MAX_TOOL_NAME_LENGTH - hash.length - 1)}_${hash}`;
|
|
28
|
+
}
|
|
29
|
+
/** `mcp__<server>`: the namespace of a server's tools. */
|
|
30
|
+
export function namespaceName(server) {
|
|
31
|
+
return `mcp__${server}`.replace(/[^A-Za-z0-9_]/g, '_');
|
|
32
|
+
}
|
|
33
|
+
function size(bytes) {
|
|
34
|
+
if (bytes < 1024)
|
|
35
|
+
return `${bytes} B`;
|
|
36
|
+
if (bytes < 1024 * 1024)
|
|
37
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
38
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
39
|
+
}
|
|
40
|
+
/** Decoded size of base64 data. */
|
|
41
|
+
const base64Bytes = (data) => Math.floor((data.length * 3) / 4) - (data.match(/=+$/)?.[0].length ?? 0);
|
|
42
|
+
/** Blobs of these types are shown as text. */
|
|
43
|
+
function isTextMimeType(mimeType) {
|
|
44
|
+
if (!mimeType)
|
|
45
|
+
return false;
|
|
46
|
+
const type = mimeType.split(';', 1)[0]?.trim().toLowerCase() ?? '';
|
|
47
|
+
return (type.startsWith('text/') ||
|
|
48
|
+
type === 'application/json' ||
|
|
49
|
+
type.endsWith('+json') ||
|
|
50
|
+
type.endsWith('+xml'));
|
|
51
|
+
}
|
|
52
|
+
/** Model-facing text of one content block. */
|
|
53
|
+
function blockText(block) {
|
|
54
|
+
switch (block.type) {
|
|
55
|
+
case 'text':
|
|
56
|
+
return block.text;
|
|
57
|
+
case 'audio':
|
|
58
|
+
return `[Audio: ${block.mimeType}, ${size(base64Bytes(block.data))} (not shown: Vela tool results are text only)]`;
|
|
59
|
+
case 'resource': {
|
|
60
|
+
const { resource } = block;
|
|
61
|
+
if ('text' in resource)
|
|
62
|
+
return resource.text;
|
|
63
|
+
if (isTextMimeType(resource.mimeType))
|
|
64
|
+
return Buffer.from(resource.blob, 'base64').toString('utf8');
|
|
65
|
+
return `[Binary resource ${resource.uri} (${resource.mimeType ?? 'unknown type'}, ${size(base64Bytes(resource.blob))}) not shown]`;
|
|
66
|
+
}
|
|
67
|
+
case 'resource_link': {
|
|
68
|
+
const details = [
|
|
69
|
+
block.mimeType,
|
|
70
|
+
block.size === undefined ? undefined : size(block.size),
|
|
71
|
+
].filter(Boolean);
|
|
72
|
+
return `[Resource ${block.uri} "${block.title ?? block.name}"${details.length ? ` (${details.join(', ')})` : ''}${block.description ? `: ${block.description}` : ''}]`;
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
return `[Unsupported content: ${block.type}]`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Text projection of an MCP result. Images are separate; absent content falls back to structured JSON. */
|
|
79
|
+
export function mcpResultText(server, tool, result) {
|
|
80
|
+
const text = result.content.length > 0
|
|
81
|
+
? result.content
|
|
82
|
+
.filter((block) => block.type !== 'image')
|
|
83
|
+
.map(blockText)
|
|
84
|
+
.join('\n')
|
|
85
|
+
: result.structuredContent === undefined
|
|
86
|
+
? ''
|
|
87
|
+
: JSON.stringify(result.structuredContent, null, 2);
|
|
88
|
+
if (result.isError &&
|
|
89
|
+
text.trim() === '' &&
|
|
90
|
+
!result.content.some((block) => block.type === 'image'))
|
|
91
|
+
return `MCP tool ${server}/${tool} returned an error`;
|
|
92
|
+
return text;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The result for Vela: text and images for the model, and `CallToolResult` without `_meta` as
|
|
96
|
+
* the native value (kept in tool history; what codemode scripts will receive). `isError` results
|
|
97
|
+
* are error results for the model.
|
|
98
|
+
*/
|
|
99
|
+
export function convertMcpResult(server, tool, result) {
|
|
100
|
+
const { _meta: _ignored, ...value } = result;
|
|
101
|
+
const content = result.content.some((block) => block.type === 'image')
|
|
102
|
+
? result.content.map((block) => block.type === 'image'
|
|
103
|
+
? {
|
|
104
|
+
type: 'image',
|
|
105
|
+
data: block.data,
|
|
106
|
+
mimeType: block.mimeType,
|
|
107
|
+
}
|
|
108
|
+
: { type: 'text', text: blockText(block) })
|
|
109
|
+
: mcpResultText(server, tool, result);
|
|
110
|
+
return new ToolExecutionResult(value, content, result.isError ? { isError: true } : {});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Tool input schemas must be objects. Servers may omit `type`, and some providers reject object
|
|
114
|
+
* schemas without `properties` (like pi).
|
|
115
|
+
*/
|
|
116
|
+
function toParameters(schema) {
|
|
117
|
+
return {
|
|
118
|
+
...schema,
|
|
119
|
+
type: schema.type ?? 'object',
|
|
120
|
+
...(schema.properties === undefined ? { properties: {} } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const ANNOTATION_HINTS = [
|
|
124
|
+
'readOnlyHint',
|
|
125
|
+
'destructiveHint',
|
|
126
|
+
'idempotentHint',
|
|
127
|
+
'openWorldHint',
|
|
128
|
+
];
|
|
129
|
+
/** The boolean hints of an MCP tool's annotations, or undefined when it has none. */
|
|
130
|
+
function toAnnotations(tool) {
|
|
131
|
+
const annotations = {};
|
|
132
|
+
for (const hint of ANNOTATION_HINTS) {
|
|
133
|
+
const value = tool.annotations?.[hint];
|
|
134
|
+
if (typeof value === 'boolean')
|
|
135
|
+
annotations[hint] = value;
|
|
136
|
+
}
|
|
137
|
+
return Object.keys(annotations).length > 0 ? annotations : undefined;
|
|
138
|
+
}
|
|
139
|
+
// Only tools built by this adapter may use its internal AI SDK JSON schemas.
|
|
140
|
+
export function createMcpTool(options) {
|
|
141
|
+
const { server, tool } = options;
|
|
142
|
+
const title = tool.title ?? tool.annotations?.title;
|
|
143
|
+
const annotations = toAnnotations(tool);
|
|
144
|
+
const definition = {
|
|
145
|
+
name: options.name,
|
|
146
|
+
description: tool.description?.trim() ||
|
|
147
|
+
title ||
|
|
148
|
+
`MCP tool ${tool.name} from server ${server}`,
|
|
149
|
+
inputSchema: jsonSchema(toParameters(tool.inputSchema)),
|
|
150
|
+
exposure: options.exposure,
|
|
151
|
+
namespace: options.namespace,
|
|
152
|
+
...(annotations ? { annotations } : {}),
|
|
153
|
+
maxResultChars: MCP_MAX_RESULT_CHARS,
|
|
154
|
+
async execute(input, context) {
|
|
155
|
+
const result = await options.caller.callTool(tool.name, input ?? {}, {
|
|
156
|
+
signal: context?.signal,
|
|
157
|
+
onProgress: (progress) => {
|
|
158
|
+
const total = progress.total === undefined ? '' : `/${progress.total}`;
|
|
159
|
+
context?.onUpdate?.(progress.message ?? `Progress ${progress.progress}${total}`);
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
return convertMcpResult(server, tool.name, result);
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
return defineJsonSchemaTool(definition);
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAMxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AAKvE,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAG/B,2EAA2E;AAC3E,MAAM,oBAAoB,GAAG,EAAE,CAAA;AAC/B,iGAAiG;AACjG,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAInC;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAAc,EACd,IAAY,EACZ,UAAqC,GAAG,EAAE,CAAC,KAAK;IAEhD,MAAM,IAAI,GAAG,QAAQ,MAAM,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAA;IACrE,IAAI,IAAI,CAAC,MAAM,IAAI,oBAAoB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IACtE,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC;SAC9B,MAAM,CAAC,GAAG,MAAM,KAAK,IAAI,EAAE,CAAC;SAC5B,MAAM,CAAC,KAAK,CAAC;SACb,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACd,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,EAAE,CAAA;AAC3E,CAAC;AAED,0DAA0D;A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AK,EAAE,CAC5D,CAAA;gBACH,CAAC;aACF,CAAC,CAAA;YACF,OAAO,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QACpD,CAAC;KACuB,CAAA;IAC1B,OAAO,oBAAoB,CAAC,UAAU,CAAC,CAAA;AACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glows777/vela-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Vela mcp package",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/glows777/Vela.git"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22.18.0",
|
|
21
|
+
"bun": ">=1.4.0"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -p tsconfig.build.json"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@glows777/vela-core": "0.5.0",
|
|
28
|
+
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
29
|
+
"ai": "^7.0.130"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"README.md",
|
|
35
|
+
"docs",
|
|
36
|
+
"examples",
|
|
37
|
+
"CHANGELOG.md"
|
|
38
|
+
],
|
|
39
|
+
"gitHead": "6b0d9c75b2f6be0d57954c9ad4b2139dc256c011"
|
|
40
|
+
}
|