@humain/terminal 0.1.1 → 0.2.2
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 +22 -0
- package/dist/bundle/chunks/{anthropic-messages-XULXUBIG.js → anthropic-messages-QFCEKGI3.js} +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-JEG2XOYC.js → azure-openai-responses-G4ZMHV37.js} +1 -1
- package/dist/bundle/chunks/chunk-7T6XCLJF.js +22 -0
- package/dist/bundle/chunks/{chunk-LYAMSPR2.js → chunk-ADQYVZ6A.js} +483 -506
- package/dist/bundle/chunks/chunk-D6HHRSB5.js +103 -0
- package/dist/bundle/chunks/{chunk-JUPSJTFQ.js → chunk-K4JAZYQH.js} +1 -1
- package/dist/bundle/chunks/{chunk-HPPQHK3J.js → chunk-KKIB2TVR.js} +1 -1
- package/dist/bundle/chunks/chunk-LI2YVPWP.js +2 -0
- package/dist/bundle/chunks/chunk-NMPIM7MN.js +2 -0
- package/dist/bundle/chunks/{chunk-BZQ53VGE.js → chunk-XSR434CO.js} +1 -1
- package/dist/bundle/chunks/compat-CN7WN6DA.js +2 -0
- package/dist/bundle/chunks/dist-PRPIUY3U.js +2 -0
- package/dist/bundle/chunks/esm-E7UVEYTO.js +4 -0
- package/dist/bundle/chunks/{extract-TRW5FBY6.js → extract-CTIFQZDJ.js} +15 -14
- package/dist/bundle/chunks/{google-generative-ai-OX6VSCA6.js → google-generative-ai-RSUU4MWO.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-GW76GSS2.js → google-vertex-CKQPOITO.js} +1 -1
- package/dist/bundle/chunks/host-WP3MVKS2.js +2 -0
- package/dist/bundle/chunks/{node-KOIP55YZ.js → node-NF43OPII.js} +1 -1
- package/dist/bundle/chunks/{node-XY3CBY3C.js → node-UMFM7CDZ.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-NPLWP6ZC.js → openai-codex-responses-S34V5ZSD.js} +1 -1
- package/dist/bundle/chunks/{openai-completions-OT2GTJKC.js → openai-completions-T2IGVUEI.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-5A6CR7GI.js → openai-responses-GYZODCT3.js} +1 -1
- package/dist/bundle/chunks/readability-LAGF34IB.js +3 -0
- package/dist/bundle/chunks/turndown.cjs-HRMZVRUL.js +2 -0
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/model-runtime.d.ts +21 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +34 -4
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +21 -8
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/subagent-env.d.ts +20 -0
- package/dist/core/tools/subagent-env.d.ts.map +1 -0
- package/dist/core/tools/subagent-env.js +47 -0
- package/dist/core/tools/subagent-env.js.map +1 -0
- package/dist/core/tools/subagent-scheduler.d.ts +36 -0
- package/dist/core/tools/subagent-scheduler.d.ts.map +1 -0
- package/dist/core/tools/subagent-scheduler.js +213 -0
- package/dist/core/tools/subagent-scheduler.js.map +1 -0
- package/dist/core/tools/subagent.d.ts +83 -3
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +215 -76
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +78 -0
- package/dist/humain/mcp-adapter/vendor/README.md +125 -19
- package/dist/humain/mcp-adapter/vendor/agent-plugin-loader.ts +69 -30
- package/dist/humain/mcp-adapter/vendor/agent-plugin-provenance.ts +36 -0
- package/dist/humain/mcp-adapter/vendor/claude-plugin-loader.ts +365 -0
- package/dist/humain/mcp-adapter/vendor/commands.ts +13 -15
- package/dist/humain/mcp-adapter/vendor/config.ts +198 -30
- package/dist/humain/mcp-adapter/vendor/consent-manager.ts +40 -9
- package/dist/humain/mcp-adapter/vendor/direct-tool-surface.ts +250 -0
- package/dist/humain/mcp-adapter/vendor/direct-tools.ts +9 -228
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.js +74 -32
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-provenance.d.ts +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-provenance.js +31 -0
- package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-provenance.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/claude-plugin-loader.d.ts +9 -0
- package/dist/humain/mcp-adapter/vendor/dist/claude-plugin-loader.js +362 -0
- package/dist/humain/mcp-adapter/vendor/dist/claude-plugin-loader.js.map +1 -0
- package/dist/humain/mcp-adapter/vendor/dist/config.d.ts +3 -1
- package/dist/humain/mcp-adapter/vendor/dist/config.js +189 -27
- package/dist/humain/mcp-adapter/vendor/dist/config.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.js +7 -16
- package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.js +5 -17
- package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/dist/types.d.ts +30 -4
- package/dist/humain/mcp-adapter/vendor/dist/types.js +26 -0
- package/dist/humain/mcp-adapter/vendor/dist/types.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/dist/utils.d.ts +6 -0
- package/dist/humain/mcp-adapter/vendor/dist/utils.js +65 -6
- package/dist/humain/mcp-adapter/vendor/dist/utils.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/host-html-template.ts +20 -19
- package/dist/humain/mcp-adapter/vendor/http-ca.ts +84 -0
- package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +37102 -15103
- package/dist/humain/mcp-adapter/vendor/index.ts +828 -164
- package/dist/humain/mcp-adapter/vendor/init.ts +48 -10
- package/dist/humain/mcp-adapter/vendor/lazy-loader.ts +7 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth-fetch.ts +113 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +256 -77
- package/dist/humain/mcp-adapter/vendor/mcp-auth.ts +316 -54
- package/dist/humain/mcp-adapter/vendor/mcp-code.ts +45 -18
- package/dist/humain/mcp-adapter/vendor/mcp-install.ts +60 -0
- package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +70 -6
- package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +53 -42
- package/dist/humain/mcp-adapter/vendor/mcp-panel-theme.ts +105 -0
- package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +366 -331
- package/dist/humain/mcp-adapter/vendor/mcp-references.ts +9 -14
- package/dist/humain/mcp-adapter/vendor/mcp-script-worker.mjs +3 -1
- package/dist/humain/mcp-adapter/vendor/mcp-setup-panel.ts +383 -341
- package/dist/humain/mcp-adapter/vendor/mcp-status.ts +5 -0
- package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +7 -16
- package/dist/humain/mcp-adapter/vendor/namespace-tools.ts +61 -3
- package/dist/humain/mcp-adapter/vendor/oauth.ts +6 -2
- package/dist/humain/mcp-adapter/vendor/package-mcp-loader.ts +5 -17
- package/dist/humain/mcp-adapter/vendor/package.json +13 -3
- package/dist/humain/mcp-adapter/vendor/prompts.ts +35 -3
- package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +108 -7
- package/dist/humain/mcp-adapter/vendor/runtime-owner.ts +16 -1
- package/dist/humain/mcp-adapter/vendor/sampling-handler.ts +9 -32
- package/dist/humain/mcp-adapter/vendor/sandbox-proxy-template.ts +20 -93
- package/dist/humain/mcp-adapter/vendor/server-manager.ts +227 -40
- package/dist/humain/mcp-adapter/vendor/session-approvals.ts +187 -0
- package/dist/humain/mcp-adapter/vendor/skills/mcp-scripting/SKILL.md +9 -1
- package/dist/humain/mcp-adapter/vendor/state.ts +10 -1
- package/dist/humain/mcp-adapter/vendor/tool-approval.ts +10 -22
- package/dist/humain/mcp-adapter/vendor/tool-metadata.ts +14 -0
- package/dist/humain/mcp-adapter/vendor/types.ts +57 -4
- package/dist/humain/mcp-adapter/vendor/ui-server.ts +36 -28
- package/dist/humain/mcp-adapter/vendor/utils.ts +64 -6
- package/dist/humain/web-access/vendor/abortable.d.ts +3 -0
- package/dist/humain/web-access/vendor/abortable.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/abortable.js +22 -0
- package/dist/humain/web-access/vendor/abortable.js.map +1 -0
- package/dist/humain/web-access/vendor/crawl4ai.d.ts +9 -0
- package/dist/humain/web-access/vendor/crawl4ai.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/crawl4ai.js +187 -0
- package/dist/humain/web-access/vendor/crawl4ai.js.map +1 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/credential-source.js +1 -0
- package/dist/humain/web-access/vendor/credential-source.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.js +20 -2
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-run.d.ts +11 -0
- package/dist/humain/web-access/vendor/curator-run.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-run.js +38 -0
- package/dist/humain/web-access/vendor/curator-run.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts +1 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.js +2 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.js +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts +1 -1
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +58 -11
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/fetch-params.js +1 -1
- package/dist/humain/web-access/vendor/fetch-params.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.d.ts +2 -2
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +12 -5
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +23 -19
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/openai-search.js +40 -14
- package/dist/humain/web-access/vendor/openai-search.js.map +1 -1
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/page-query.js +6 -2
- package/dist/humain/web-access/vendor/page-query.js.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.js +6 -2
- package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -1
- package/dist/humain/web-access/vendor/serpapi.d.ts +4 -0
- package/dist/humain/web-access/vendor/serpapi.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/serpapi.js +215 -0
- package/dist/humain/web-access/vendor/serpapi.js.map +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ssrf-protection.js +5 -1
- package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -1
- package/dist/humain/web-access/vendor/storage.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/storage.js +9 -0
- package/dist/humain/web-access/vendor/storage.js.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.d.ts +1 -1
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.js +35 -24
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +5 -3
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/modes/json-event.d.ts +8 -0
- package/dist/modes/json-event.d.ts.map +1 -1
- package/dist/modes/json-event.js +17 -0
- package/dist/modes/json-event.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +3 -2
- package/dist/modes/print-mode.js.map +1 -1
- package/docs/environment-variables.md +9 -0
- package/docs/json.md +16 -0
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/src/humain/mcp-adapter/UPSTREAM.md +56 -7
- package/src/humain/mcp-adapter/upstream.json +6 -4
- package/src/humain/mcp-adapter/vendor/CHANGELOG.md +78 -0
- package/src/humain/web-access/UPSTREAM.md +18 -8
- package/src/humain/web-access/upstream.json +6 -5
- package/dist/bundle/chunks/chunk-2LC3S3VV.js +0 -105
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { Check, Errors } from "typebox/value";
|
|
2
|
+
import type { DirectToolSpec, McpConfig, ToolPrefix } from "./types.ts";
|
|
3
|
+
import { createToolSelectorCandidateIndex, formatToolName, getToolNameCandidates, isServerDisabled, isToolAllowed, resolveToolPrefix } from "./types.ts";
|
|
4
|
+
import type { MetadataCache } from "./metadata-cache.ts";
|
|
5
|
+
import { isServerCacheValid, parseDirectToolSelectors } from "./metadata-cache.ts";
|
|
6
|
+
export { getMissingConfiguredDirectToolServers } from "./metadata-cache.ts";
|
|
7
|
+
import { isUiToolVisibleToModel } from "./ui-tool-visibility.ts";
|
|
8
|
+
import { resourceNameToToolName } from "./resource-tools.ts";
|
|
9
|
+
|
|
10
|
+
const BUILTIN_NAMES = new Set(["read", "bash", "edit", "write", "grep", "find", "ls", "mcp"]);
|
|
11
|
+
export const DIRECT_TOOLS_ADVISORY_THRESHOLD = 75;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Recover one model-emitted JSON layer for schema-declared object and array
|
|
15
|
+
* properties, then validate the complete input against the same schema.
|
|
16
|
+
*/
|
|
17
|
+
export function prepareDirectToolArguments(inputSchema: unknown, args: unknown): unknown {
|
|
18
|
+
if (!inputSchema || typeof inputSchema !== "object" || Array.isArray(inputSchema)) return args;
|
|
19
|
+
const schema = inputSchema as Record<string, unknown>;
|
|
20
|
+
if (schema.type !== "object") return args;
|
|
21
|
+
const input = args && typeof args === "object" && !Array.isArray(args)
|
|
22
|
+
? args as Record<string, unknown>
|
|
23
|
+
: null;
|
|
24
|
+
const properties = schema.properties;
|
|
25
|
+
let prepared: Record<string, unknown> | undefined;
|
|
26
|
+
|
|
27
|
+
if (input && properties && typeof properties === "object" && !Array.isArray(properties)) {
|
|
28
|
+
for (const [name, propertySchema] of Object.entries(properties)) {
|
|
29
|
+
if (!Object.hasOwn(input, name) || typeof input[name] !== "string"
|
|
30
|
+
|| !propertySchema || typeof propertySchema !== "object" || Array.isArray(propertySchema)) continue;
|
|
31
|
+
const expectedType = (propertySchema as Record<string, unknown>).type;
|
|
32
|
+
if (expectedType !== "object" && expectedType !== "array") continue;
|
|
33
|
+
try {
|
|
34
|
+
const parsed: unknown = JSON.parse(input[name] as string);
|
|
35
|
+
const matches = expectedType === "array"
|
|
36
|
+
? Array.isArray(parsed)
|
|
37
|
+
: parsed !== null && typeof parsed === "object" && !Array.isArray(parsed);
|
|
38
|
+
if (matches) {
|
|
39
|
+
prepared ??= { ...input };
|
|
40
|
+
prepared[name] = parsed;
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
// Validation below reports malformed or shape-incompatible values.
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const candidate = prepared ?? args;
|
|
49
|
+
if (!Check(inputSchema as never, candidate)) {
|
|
50
|
+
const errors = Errors(inputSchema as never, candidate);
|
|
51
|
+
const issues = errors.slice(0, 8).map((error) => ({
|
|
52
|
+
instancePath: error.instancePath || "/",
|
|
53
|
+
keyword: error.keyword,
|
|
54
|
+
message: error.message,
|
|
55
|
+
}));
|
|
56
|
+
throw new TypeError(`MCP direct tool arguments do not match the advertised input schema: ${JSON.stringify({
|
|
57
|
+
issues,
|
|
58
|
+
total: errors.length,
|
|
59
|
+
truncated: errors.length > issues.length,
|
|
60
|
+
})}`);
|
|
61
|
+
}
|
|
62
|
+
return candidate;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function resolveDirectTools(
|
|
66
|
+
config: McpConfig,
|
|
67
|
+
cache: MetadataCache | null,
|
|
68
|
+
prefix: ToolPrefix,
|
|
69
|
+
envOverride?: string[],
|
|
70
|
+
unavailableServers: ReadonlySet<string> = new Set(),
|
|
71
|
+
reservedNames?: Set<string>,
|
|
72
|
+
): DirectToolSpec[] {
|
|
73
|
+
const specs: DirectToolSpec[] = [];
|
|
74
|
+
if (!cache) return specs;
|
|
75
|
+
|
|
76
|
+
const seenNames = new Set<string>();
|
|
77
|
+
|
|
78
|
+
const envSelection = envOverride ? parseDirectToolSelectors(envOverride) : null;
|
|
79
|
+
const globalDirect = config.settings?.directTools;
|
|
80
|
+
|
|
81
|
+
for (const [serverName, definition] of Object.entries(config.mcpServers)) {
|
|
82
|
+
if (isServerDisabled(definition)) continue;
|
|
83
|
+
const serverCache = cache.servers[serverName];
|
|
84
|
+
if (!serverCache || !isServerCacheValid(serverCache, definition)) continue;
|
|
85
|
+
|
|
86
|
+
let toolFilter: true | string[] | false = false;
|
|
87
|
+
let lazy = false;
|
|
88
|
+
|
|
89
|
+
if (envSelection) {
|
|
90
|
+
if (envSelection.servers.has(serverName)) {
|
|
91
|
+
toolFilter = true;
|
|
92
|
+
} else if (envSelection.tools.has(serverName)) {
|
|
93
|
+
toolFilter = [...envSelection.tools.get(serverName)!];
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
const selected = definition.directTools !== undefined ? definition.directTools : globalDirect;
|
|
97
|
+
if (selected === "search") {
|
|
98
|
+
// Real tools with real schemas, but registered inactive; the model
|
|
99
|
+
// reaches them through mcp({ search }), which activates the matches.
|
|
100
|
+
toolFilter = true;
|
|
101
|
+
lazy = true;
|
|
102
|
+
} else if (selected !== undefined) {
|
|
103
|
+
toolFilter = selected;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!toolFilter) continue;
|
|
108
|
+
|
|
109
|
+
const effectivePrefix = resolveToolPrefix(definition, prefix);
|
|
110
|
+
const hasToolFilters =
|
|
111
|
+
(Array.isArray(definition.includeTools) && definition.includeTools.length > 0) ||
|
|
112
|
+
(Array.isArray(definition.excludeTools) && definition.excludeTools.length > 0);
|
|
113
|
+
const selectorCandidateIndex = hasToolFilters ? (() => {
|
|
114
|
+
const candidates = new Set<string>();
|
|
115
|
+
for (const [otherServerName, otherDefinition] of Object.entries(config.mcpServers)) {
|
|
116
|
+
const otherCache = cache.servers[otherServerName];
|
|
117
|
+
if (!otherCache || !isServerCacheValid(otherCache, otherDefinition) || isServerDisabled(otherDefinition)) continue;
|
|
118
|
+
const otherPrefix = resolveToolPrefix(otherDefinition, prefix);
|
|
119
|
+
for (const otherTool of otherCache.tools ?? []) {
|
|
120
|
+
if (!isUiToolVisibleToModel(otherTool.uiVisibility)) continue;
|
|
121
|
+
for (const candidate of getToolNameCandidates(otherTool.name, otherServerName, otherPrefix, false)) candidates.add(candidate);
|
|
122
|
+
}
|
|
123
|
+
if (otherDefinition.exposeResources !== false) {
|
|
124
|
+
for (const resource of otherCache.resources ?? []) {
|
|
125
|
+
const baseName = `read_${resourceNameToToolName(resource.name)}`;
|
|
126
|
+
for (const candidate of getToolNameCandidates(baseName, otherServerName, otherPrefix, false)) candidates.add(candidate);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return createToolSelectorCandidateIndex(candidates);
|
|
131
|
+
})() : undefined;
|
|
132
|
+
|
|
133
|
+
for (const tool of serverCache.tools ?? []) {
|
|
134
|
+
if (!isUiToolVisibleToModel(tool.uiVisibility)) continue;
|
|
135
|
+
if (toolFilter !== true && !toolFilter.includes(tool.name)) continue;
|
|
136
|
+
if (!isToolAllowed(tool.name, serverName, effectivePrefix, definition.includeTools, definition.excludeTools, selectorCandidateIndex)) continue;
|
|
137
|
+
const prefixedName = formatToolName(tool.name, serverName, effectivePrefix);
|
|
138
|
+
if (BUILTIN_NAMES.has(prefixedName)) {
|
|
139
|
+
console.warn(`MCP: skipping direct tool "${prefixedName}" (collides with builtin)`);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (seenNames.has(prefixedName)) {
|
|
143
|
+
console.warn(`MCP: skipping duplicate direct tool "${prefixedName}" from "${serverName}"`);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
seenNames.add(prefixedName);
|
|
147
|
+
specs.push({
|
|
148
|
+
...(lazy ? { lazy: true } : {}),
|
|
149
|
+
serverName,
|
|
150
|
+
originalName: tool.name,
|
|
151
|
+
prefixedName,
|
|
152
|
+
description: tool.description ?? "",
|
|
153
|
+
...(tool.inputSchema !== undefined ? { inputSchema: tool.inputSchema } : {}),
|
|
154
|
+
...(tool.uiResourceUri !== undefined ? { uiResourceUri: tool.uiResourceUri } : {}),
|
|
155
|
+
...(tool.uiStreamMode !== undefined ? { uiStreamMode: tool.uiStreamMode } : {}),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (definition.exposeResources !== false) {
|
|
160
|
+
for (const resource of serverCache.resources ?? []) {
|
|
161
|
+
const baseName = `read_${resourceNameToToolName(resource.name)}`;
|
|
162
|
+
if (toolFilter !== true && !toolFilter.includes(baseName)) continue;
|
|
163
|
+
if (!isToolAllowed(baseName, serverName, effectivePrefix, definition.includeTools, definition.excludeTools, selectorCandidateIndex)) continue;
|
|
164
|
+
const prefixedName = formatToolName(baseName, serverName, effectivePrefix);
|
|
165
|
+
if (BUILTIN_NAMES.has(prefixedName)) {
|
|
166
|
+
console.warn(`MCP: skipping direct resource tool "${prefixedName}" (collides with builtin)`);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (seenNames.has(prefixedName)) {
|
|
170
|
+
console.warn(`MCP: skipping duplicate direct resource tool "${prefixedName}" from "${serverName}"`);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
seenNames.add(prefixedName);
|
|
174
|
+
specs.push({
|
|
175
|
+
...(lazy ? { lazy: true } : {}),
|
|
176
|
+
serverName,
|
|
177
|
+
originalName: baseName,
|
|
178
|
+
prefixedName,
|
|
179
|
+
description: resource.description ?? `Read resource: ${resource.uri}`,
|
|
180
|
+
resourceUri: resource.uri,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
for (const spec of specs) reservedNames?.add(spec.prefixedName);
|
|
187
|
+
|
|
188
|
+
const emittedSpecs = unavailableServers.size === 0
|
|
189
|
+
? specs
|
|
190
|
+
: specs.filter((spec) => !unavailableServers.has(spec.serverName));
|
|
191
|
+
|
|
192
|
+
// Lazy specs cost nothing at turn start, so they do not count toward the advisory.
|
|
193
|
+
const eagerCount = emittedSpecs.filter((spec) => !spec.lazy).length;
|
|
194
|
+
if (config.settings?.warnOnLargeDirectTools !== false && eagerCount >= DIRECT_TOOLS_ADVISORY_THRESHOLD) {
|
|
195
|
+
console.warn(`MCP: ${eagerCount} direct tools resolved. Each direct tool adds prompt context; README guidance recommends targeted sets of 5-20 tools and using the proxy or an explicit string[] when 75+ direct tools would be registered. Set settings.warnOnLargeDirectTools to false to hide this advisory.`);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return emittedSpecs;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Pure function of config: the description must stay byte-stable across
|
|
203
|
+
* runtime metadata changes (tool counts, instructions, connection state) so
|
|
204
|
+
* re-registering the proxy tool never rewrites the cached prompt prefix.
|
|
205
|
+
* Live counts/status belong to `mcp({ })`, full instructions to
|
|
206
|
+
* `mcp({ instructions })`.
|
|
207
|
+
*/
|
|
208
|
+
export function buildProxyDescription(config: McpConfig): string {
|
|
209
|
+
let desc = `MCP gateway — URL installation, server status, tool search/describe, auth, and single MCP tool calls. When a user supplies an MCP endpoint URL, install it with the install action. When one request needs several MCP calls with logic between them, use mcpScript. Non-MCP Pi tools should be called directly, not through mcp.\n`;
|
|
210
|
+
|
|
211
|
+
const serverNames = Object.keys(config.mcpServers)
|
|
212
|
+
.filter((serverName) => !isServerDisabled(config.mcpServers[serverName]));
|
|
213
|
+
if (serverNames.length > 0) {
|
|
214
|
+
desc += `\nServers: ${serverNames.join(", ")}\n`;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Search-mode tools are real tools held inactive. Say how they wake up, or
|
|
218
|
+
// the model reads mcp({ tool }) as the only way in and never gets a schema.
|
|
219
|
+
const searchModeServers = serverNames.filter((serverName) => {
|
|
220
|
+
const definition = config.mcpServers[serverName];
|
|
221
|
+
const selected = definition?.directTools !== undefined ? definition.directTools : config.settings?.directTools;
|
|
222
|
+
return selected === "search";
|
|
223
|
+
});
|
|
224
|
+
if (searchModeServers.length > 0) {
|
|
225
|
+
desc += `\nSearch-mode servers (${searchModeServers.join(", ")}): their tools become real, schema-backed tools the first time mcp({ search }) matches them — after that, call them directly by name.\n`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const disabledServers = Object.entries(config.mcpServers)
|
|
229
|
+
.filter(([, definition]) => isServerDisabled(definition))
|
|
230
|
+
.map(([serverName]) => serverName);
|
|
231
|
+
if (disabledServers.length > 0) {
|
|
232
|
+
desc += `\nDisabled servers (enable with /mcp enable <server> and /reload): ${disabledServers.join(", ")}\n`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
desc += `\nUsage:\n`;
|
|
236
|
+
desc += ` mcp({ action: "install", url: "https://example.com/mcp" }) → Install, connect, and authenticate an MCP URL\n`;
|
|
237
|
+
desc += ` mcp({ }) → Show server status and tool counts\n`;
|
|
238
|
+
desc += ` mcp({ server: "name" }) → List tools from server\n`;
|
|
239
|
+
desc += ` mcp({ search: "query" }) → Search MCP tools by name/description\n`;
|
|
240
|
+
desc += ` mcp({ describe: "tool_name" }) → Show tool details and parameters\n`;
|
|
241
|
+
desc += ` mcp({ instructions: "name" }) → Show full server usage instructions\n`;
|
|
242
|
+
desc += ` mcp({ connect: "server-name" }) → Connect to a server and refresh metadata\n`;
|
|
243
|
+
desc += ` mcp({ tool: "name", args: { key: "value" } }) → Call a tool (object args; JSON string also accepted)\n`;
|
|
244
|
+
desc += ` mcp({ action: "ui-messages" }) → Retrieve accumulated messages from completed UI sessions\n`;
|
|
245
|
+
desc += ` mcp({ action: "auth-start", server: "name" }) → Open OAuth and watch for completion\n`;
|
|
246
|
+
desc += ` mcp({ action: "auth-complete", server: "name", args: { redirectUrl: "..." } }) → Complete manual OAuth\n`;
|
|
247
|
+
desc += `\nMode: action > tool (call) > connect > describe > instructions > search > server (list) > nothing (status)`;
|
|
248
|
+
|
|
249
|
+
return desc;
|
|
250
|
+
}
|
|
@@ -1,89 +1,36 @@
|
|
|
1
1
|
import type { AgentToolResult, AgentToolUpdateCallback, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { UrlElicitationRequiredError, type Client } from "@modelcontextprotocol/client";
|
|
3
3
|
import type { McpExtensionState } from "./state.ts";
|
|
4
|
-
import type { DirectToolSpec,
|
|
5
|
-
import type { MetadataCache } from "./metadata-cache.ts";
|
|
4
|
+
import type { DirectToolSpec, McpContent } from "./types.ts";
|
|
6
5
|
import { lazyConnect, getFailureAgeSeconds, clearFailure } from "./init.ts";
|
|
7
6
|
import { abortable, throwIfAborted } from "./abort.ts";
|
|
8
|
-
import { isServerCacheValid, parseDirectToolSelectors } from "./metadata-cache.ts";
|
|
9
|
-
export { getMissingConfiguredDirectToolServers } from "./metadata-cache.ts";
|
|
10
7
|
import { formatSchema } from "./tool-metadata.ts";
|
|
11
8
|
import { resolveMcpResultContent, transformMcpContent, transformMcpResourceContents } from "./tool-registrar.ts";
|
|
12
9
|
import { guardMcpOutput, guardedMcpDetails, resolveMcpOutputGuardOptions } from "./mcp-output-guard.ts";
|
|
13
10
|
import { maybeStartUiSession, summarizeUiSessionResult, type UiSessionRuntime } from "./ui-session.ts";
|
|
14
|
-
import {
|
|
15
|
-
import { isUiToolVisibleToModel } from "./ui-tool-visibility.ts";
|
|
16
|
-
import { resourceNameToToolName } from "./resource-tools.ts";
|
|
11
|
+
import { isServerDisabled } from "./types.ts";
|
|
17
12
|
import { authenticate, supportsOAuth } from "./mcp-auth-flow.ts";
|
|
18
13
|
import { formatAuthRequiredMessage, normalizeToolArguments, resolveServerUrl } from "./utils.ts";
|
|
19
14
|
import { SessionRecoveryAuthRequiredError, withSessionRecovery } from "./session-recovery.ts";
|
|
20
15
|
import { combineAbortSignals, isAbortError } from "./runtime-owner.ts";
|
|
21
16
|
import { ensureToolCallApproved } from "./tool-approval.ts";
|
|
22
|
-
import { Check, Errors } from "typebox/value";
|
|
23
17
|
import { getInputRequiredNeedsUiDetails } from "./errors.ts";
|
|
24
18
|
|
|
25
19
|
type ClientCallToolResult = Awaited<ReturnType<Client["callTool"]>>;
|
|
26
20
|
type ClientReadResourceResult = Awaited<ReturnType<Client["readResource"]>>;
|
|
27
21
|
|
|
28
|
-
const BUILTIN_NAMES = new Set(["read", "bash", "edit", "write", "grep", "find", "ls", "mcp"]);
|
|
29
|
-
export const DIRECT_TOOLS_ADVISORY_THRESHOLD = 75;
|
|
30
|
-
|
|
31
22
|
type DirectAutoAuthResult =
|
|
32
23
|
| { status: "skipped" }
|
|
33
24
|
| { status: "success" }
|
|
34
25
|
| { status: "failed"; message: string };
|
|
35
26
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (schema.type !== "object") return args;
|
|
44
|
-
const input = args && typeof args === "object" && !Array.isArray(args)
|
|
45
|
-
? args as Record<string, unknown>
|
|
46
|
-
: null;
|
|
47
|
-
const properties = schema.properties;
|
|
48
|
-
let prepared: Record<string, unknown> | undefined;
|
|
49
|
-
|
|
50
|
-
if (input && properties && typeof properties === "object" && !Array.isArray(properties)) {
|
|
51
|
-
for (const [name, propertySchema] of Object.entries(properties)) {
|
|
52
|
-
if (!Object.hasOwn(input, name) || typeof input[name] !== "string"
|
|
53
|
-
|| !propertySchema || typeof propertySchema !== "object" || Array.isArray(propertySchema)) continue;
|
|
54
|
-
const expectedType = (propertySchema as Record<string, unknown>).type;
|
|
55
|
-
if (expectedType !== "object" && expectedType !== "array") continue;
|
|
56
|
-
try {
|
|
57
|
-
const parsed: unknown = JSON.parse(input[name] as string);
|
|
58
|
-
const matches = expectedType === "array"
|
|
59
|
-
? Array.isArray(parsed)
|
|
60
|
-
: parsed !== null && typeof parsed === "object" && !Array.isArray(parsed);
|
|
61
|
-
if (matches) {
|
|
62
|
-
prepared ??= { ...input };
|
|
63
|
-
prepared[name] = parsed;
|
|
64
|
-
}
|
|
65
|
-
} catch {
|
|
66
|
-
// Validation below reports malformed or shape-incompatible values.
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const candidate = prepared ?? args;
|
|
72
|
-
if (!Check(inputSchema as never, candidate)) {
|
|
73
|
-
const errors = Errors(inputSchema as never, candidate);
|
|
74
|
-
const issues = errors.slice(0, 8).map((error) => ({
|
|
75
|
-
instancePath: error.instancePath || "/",
|
|
76
|
-
keyword: error.keyword,
|
|
77
|
-
message: error.message,
|
|
78
|
-
}));
|
|
79
|
-
throw new TypeError(`MCP direct tool arguments do not match the advertised input schema: ${JSON.stringify({
|
|
80
|
-
issues,
|
|
81
|
-
total: errors.length,
|
|
82
|
-
truncated: errors.length > issues.length,
|
|
83
|
-
})}`);
|
|
84
|
-
}
|
|
85
|
-
return candidate;
|
|
86
|
-
}
|
|
27
|
+
export {
|
|
28
|
+
DIRECT_TOOLS_ADVISORY_THRESHOLD,
|
|
29
|
+
buildProxyDescription,
|
|
30
|
+
getMissingConfiguredDirectToolServers,
|
|
31
|
+
prepareDirectToolArguments,
|
|
32
|
+
resolveDirectTools,
|
|
33
|
+
} from "./direct-tool-surface.ts";
|
|
87
34
|
|
|
88
35
|
function getDirectAuthRequiredMessage(
|
|
89
36
|
state: McpExtensionState,
|
|
@@ -165,172 +112,6 @@ async function attemptDirectAutoAuth(
|
|
|
165
112
|
}
|
|
166
113
|
}
|
|
167
114
|
|
|
168
|
-
export function resolveDirectTools(
|
|
169
|
-
config: McpConfig,
|
|
170
|
-
cache: MetadataCache | null,
|
|
171
|
-
prefix: ToolPrefix,
|
|
172
|
-
envOverride?: string[],
|
|
173
|
-
unavailableServers: ReadonlySet<string> = new Set(),
|
|
174
|
-
reservedNames?: Set<string>,
|
|
175
|
-
): DirectToolSpec[] {
|
|
176
|
-
const specs: DirectToolSpec[] = [];
|
|
177
|
-
if (!cache) return specs;
|
|
178
|
-
|
|
179
|
-
const seenNames = new Set<string>();
|
|
180
|
-
|
|
181
|
-
const envSelection = envOverride ? parseDirectToolSelectors(envOverride) : null;
|
|
182
|
-
const globalDirect = config.settings?.directTools;
|
|
183
|
-
|
|
184
|
-
for (const [serverName, definition] of Object.entries(config.mcpServers)) {
|
|
185
|
-
if (isServerDisabled(definition)) continue;
|
|
186
|
-
const serverCache = cache.servers[serverName];
|
|
187
|
-
if (!serverCache || !isServerCacheValid(serverCache, definition)) continue;
|
|
188
|
-
|
|
189
|
-
let toolFilter: true | string[] | false = false;
|
|
190
|
-
|
|
191
|
-
if (envSelection) {
|
|
192
|
-
if (envSelection.servers.has(serverName)) {
|
|
193
|
-
toolFilter = true;
|
|
194
|
-
} else if (envSelection.tools.has(serverName)) {
|
|
195
|
-
toolFilter = [...envSelection.tools.get(serverName)!];
|
|
196
|
-
}
|
|
197
|
-
} else {
|
|
198
|
-
if (definition.directTools !== undefined) {
|
|
199
|
-
toolFilter = definition.directTools;
|
|
200
|
-
} else if (globalDirect) {
|
|
201
|
-
toolFilter = globalDirect;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (!toolFilter) continue;
|
|
206
|
-
|
|
207
|
-
const effectivePrefix = resolveToolPrefix(definition, prefix);
|
|
208
|
-
const hasToolFilters =
|
|
209
|
-
(Array.isArray(definition.includeTools) && definition.includeTools.length > 0) ||
|
|
210
|
-
(Array.isArray(definition.excludeTools) && definition.excludeTools.length > 0);
|
|
211
|
-
const selectorCandidateIndex = hasToolFilters ? (() => {
|
|
212
|
-
const candidates = new Set<string>();
|
|
213
|
-
for (const [otherServerName, otherDefinition] of Object.entries(config.mcpServers)) {
|
|
214
|
-
const otherCache = cache.servers[otherServerName];
|
|
215
|
-
if (!otherCache || !isServerCacheValid(otherCache, otherDefinition) || isServerDisabled(otherDefinition)) continue;
|
|
216
|
-
const otherPrefix = resolveToolPrefix(otherDefinition, prefix);
|
|
217
|
-
for (const otherTool of otherCache.tools ?? []) {
|
|
218
|
-
if (!isUiToolVisibleToModel(otherTool.uiVisibility)) continue;
|
|
219
|
-
for (const candidate of getToolNameCandidates(otherTool.name, otherServerName, otherPrefix, false)) candidates.add(candidate);
|
|
220
|
-
}
|
|
221
|
-
if (otherDefinition.exposeResources !== false) {
|
|
222
|
-
for (const resource of otherCache.resources ?? []) {
|
|
223
|
-
const baseName = `read_${resourceNameToToolName(resource.name)}`;
|
|
224
|
-
for (const candidate of getToolNameCandidates(baseName, otherServerName, otherPrefix, false)) candidates.add(candidate);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return createToolSelectorCandidateIndex(candidates);
|
|
229
|
-
})() : undefined;
|
|
230
|
-
|
|
231
|
-
for (const tool of serverCache.tools ?? []) {
|
|
232
|
-
if (!isUiToolVisibleToModel(tool.uiVisibility)) continue;
|
|
233
|
-
if (toolFilter !== true && !toolFilter.includes(tool.name)) continue;
|
|
234
|
-
if (!isToolAllowed(tool.name, serverName, effectivePrefix, definition.includeTools, definition.excludeTools, selectorCandidateIndex)) continue;
|
|
235
|
-
const prefixedName = formatToolName(tool.name, serverName, effectivePrefix);
|
|
236
|
-
if (BUILTIN_NAMES.has(prefixedName)) {
|
|
237
|
-
console.warn(`MCP: skipping direct tool "${prefixedName}" (collides with builtin)`);
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
if (seenNames.has(prefixedName)) {
|
|
241
|
-
console.warn(`MCP: skipping duplicate direct tool "${prefixedName}" from "${serverName}"`);
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
seenNames.add(prefixedName);
|
|
245
|
-
specs.push({
|
|
246
|
-
serverName,
|
|
247
|
-
originalName: tool.name,
|
|
248
|
-
prefixedName,
|
|
249
|
-
description: tool.description ?? "",
|
|
250
|
-
...(tool.inputSchema !== undefined ? { inputSchema: tool.inputSchema } : {}),
|
|
251
|
-
...(tool.uiResourceUri !== undefined ? { uiResourceUri: tool.uiResourceUri } : {}),
|
|
252
|
-
...(tool.uiStreamMode !== undefined ? { uiStreamMode: tool.uiStreamMode } : {}),
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (definition.exposeResources !== false) {
|
|
257
|
-
for (const resource of serverCache.resources ?? []) {
|
|
258
|
-
const baseName = `read_${resourceNameToToolName(resource.name)}`;
|
|
259
|
-
if (toolFilter !== true && !toolFilter.includes(baseName)) continue;
|
|
260
|
-
if (!isToolAllowed(baseName, serverName, effectivePrefix, definition.includeTools, definition.excludeTools, selectorCandidateIndex)) continue;
|
|
261
|
-
const prefixedName = formatToolName(baseName, serverName, effectivePrefix);
|
|
262
|
-
if (BUILTIN_NAMES.has(prefixedName)) {
|
|
263
|
-
console.warn(`MCP: skipping direct resource tool "${prefixedName}" (collides with builtin)`);
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
if (seenNames.has(prefixedName)) {
|
|
267
|
-
console.warn(`MCP: skipping duplicate direct resource tool "${prefixedName}" from "${serverName}"`);
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
seenNames.add(prefixedName);
|
|
271
|
-
specs.push({
|
|
272
|
-
serverName,
|
|
273
|
-
originalName: baseName,
|
|
274
|
-
prefixedName,
|
|
275
|
-
description: resource.description ?? `Read resource: ${resource.uri}`,
|
|
276
|
-
resourceUri: resource.uri,
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
for (const spec of specs) reservedNames?.add(spec.prefixedName);
|
|
283
|
-
|
|
284
|
-
const emittedSpecs = unavailableServers.size === 0
|
|
285
|
-
? specs
|
|
286
|
-
: specs.filter((spec) => !unavailableServers.has(spec.serverName));
|
|
287
|
-
|
|
288
|
-
if (config.settings?.warnOnLargeDirectTools !== false && emittedSpecs.length >= DIRECT_TOOLS_ADVISORY_THRESHOLD) {
|
|
289
|
-
console.warn(`MCP: ${emittedSpecs.length} direct tools resolved. Each direct tool adds prompt context; README guidance recommends targeted sets of 5-20 tools and using the proxy or an explicit string[] when 75+ direct tools would be registered. Set settings.warnOnLargeDirectTools to false to hide this advisory.`);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return emittedSpecs;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Pure function of config: the description must stay byte-stable across
|
|
297
|
-
* runtime metadata changes (tool counts, instructions, connection state) so
|
|
298
|
-
* re-registering the proxy tool never rewrites the cached prompt prefix.
|
|
299
|
-
* Live counts/status belong to `mcp({ })`, full instructions to
|
|
300
|
-
* `mcp({ instructions })`.
|
|
301
|
-
*/
|
|
302
|
-
export function buildProxyDescription(config: McpConfig): string {
|
|
303
|
-
let desc = `MCP gateway — server status, tool search/describe, auth, and single MCP tool calls. When one request needs several MCP calls with logic between them, use mcpScript. Non-MCP Pi tools should be called directly, not through mcp.\n`;
|
|
304
|
-
|
|
305
|
-
const serverNames = Object.keys(config.mcpServers)
|
|
306
|
-
.filter((serverName) => !isServerDisabled(config.mcpServers[serverName]));
|
|
307
|
-
if (serverNames.length > 0) {
|
|
308
|
-
desc += `\nServers: ${serverNames.join(", ")}\n`;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const disabledServers = Object.entries(config.mcpServers)
|
|
312
|
-
.filter(([, definition]) => isServerDisabled(definition))
|
|
313
|
-
.map(([serverName]) => serverName);
|
|
314
|
-
if (disabledServers.length > 0) {
|
|
315
|
-
desc += `\nDisabled servers (enable with /mcp enable <server> and /reload): ${disabledServers.join(", ")}\n`;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
desc += `\nUsage:\n`;
|
|
319
|
-
desc += ` mcp({ }) → Show server status and tool counts\n`;
|
|
320
|
-
desc += ` mcp({ server: "name" }) → List tools from server\n`;
|
|
321
|
-
desc += ` mcp({ search: "query" }) → Search MCP tools by name/description\n`;
|
|
322
|
-
desc += ` mcp({ describe: "tool_name" }) → Show tool details and parameters\n`;
|
|
323
|
-
desc += ` mcp({ instructions: "name" }) → Show full server usage instructions\n`;
|
|
324
|
-
desc += ` mcp({ connect: "server-name" }) → Connect to a server and refresh metadata\n`;
|
|
325
|
-
desc += ` mcp({ tool: "name", args: { key: "value" } }) → Call a tool (object args; JSON string also accepted)\n`;
|
|
326
|
-
desc += ` mcp({ action: "ui-messages" }) → Retrieve accumulated messages from completed UI sessions\n`;
|
|
327
|
-
desc += ` mcp({ action: "auth-start", server: "name" }) → Start manual OAuth and get a browser URL\n`;
|
|
328
|
-
desc += ` mcp({ action: "auth-complete", server: "name", args: { redirectUrl: "..." } }) → Complete manual OAuth\n`;
|
|
329
|
-
desc += `\nMode: action > tool (call) > connect > describe > instructions > search > server (list) > nothing (status)`;
|
|
330
|
-
|
|
331
|
-
return desc;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
115
|
type DirectToolExecute = (
|
|
335
116
|
toolCallId: string,
|
|
336
117
|
params: Record<string, unknown>,
|