@sharpe-terminal/mcp-server 1.4.0 → 1.6.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/README.md +17 -7
- package/dist/api-client.d.ts +38 -1
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +119 -10
- package/dist/api-client.js.map +1 -1
- package/dist/composite-tools.d.ts +27 -45
- package/dist/composite-tools.d.ts.map +1 -1
- package/dist/composite-tools.js +372 -546
- package/dist/composite-tools.js.map +1 -1
- package/dist/contracts/manifest.d.ts +52 -0
- package/dist/contracts/manifest.d.ts.map +1 -0
- package/dist/contracts/manifest.js +9 -0
- package/dist/contracts/manifest.js.map +1 -0
- package/dist/endpoint-tools.d.ts +107 -0
- package/dist/endpoint-tools.d.ts.map +1 -0
- package/dist/endpoint-tools.js +382 -0
- package/dist/endpoint-tools.js.map +1 -0
- package/dist/server.d.ts +20 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +143 -101
- package/dist/server.js.map +1 -1
- package/dist/tool-runtime.d.ts +33 -38
- package/dist/tool-runtime.d.ts.map +1 -1
- package/dist/tool-runtime.js +113 -238
- package/dist/tool-runtime.js.map +1 -1
- package/package.json +1 -1
- package/dist/tools.d.ts +0 -567
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -1166
- package/dist/tools.js.map +0 -1
package/dist/server.js
CHANGED
|
@@ -2,13 +2,22 @@
|
|
|
2
2
|
* The Sharpe MCP server, independent of transport: the stdio entry point
|
|
3
3
|
* (index.ts) and the hosted Streamable HTTP endpoint (/api/mcp on
|
|
4
4
|
* www.sharpe.ai) both build their server here, so the two cannot drift.
|
|
5
|
+
*
|
|
6
|
+
* Endpoint tools are data (WP-U12): tools/list serves each one's name, title,
|
|
7
|
+
* description and input JSON Schema (and its output schema, when the manifest
|
|
8
|
+
* publishes them) exactly as the synced agent manifest renders them from
|
|
9
|
+
* src/contracts (endpoint-tools.ts), and the Python server serves the same
|
|
10
|
+
* document. The three composite tools format several
|
|
11
|
+
* endpoints into one report and keep their own schemas.
|
|
5
12
|
*/
|
|
6
13
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
14
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
7
15
|
import { z } from "zod/v3";
|
|
8
|
-
import { TOOL_DEFS } from "./tools.js";
|
|
9
16
|
import { analyzeCoin, marketBriefing, findOpportunities, } from "./composite-tools.js";
|
|
17
|
+
import { MANIFEST } from "./contracts/manifest.js";
|
|
18
|
+
import { ENDPOINT_TOOLS, callEndpointTool, propertyIssue, } from "./endpoint-tools.js";
|
|
10
19
|
import { FUTURES_CHARTS, EXCHANGES_DATA, NARRATIVE_SLUGS, ECOSYSTEM_SLUGS, } from "./resources.js";
|
|
11
|
-
import {
|
|
20
|
+
import { READ_ONLY_MARKET_DATA_TOOL_ANNOTATIONS, toStructuredToolResult, toTextErrorResult, toTextToolResult, toToolErrorResult, } from "./tool-runtime.js";
|
|
12
21
|
/** Sent at initialize: how an agent should pick among the 40 tools. */
|
|
13
22
|
const SERVER_INSTRUCTIONS = [
|
|
14
23
|
"Sharpe provides crypto derivatives and market data covering funding rates across 32 venues, futures across 10 exchanges, arbitrage, listings, narratives, ecosystems, and news.",
|
|
@@ -30,120 +39,153 @@ const SERVER_INSTRUCTIONS = [
|
|
|
30
39
|
"get_token_scanner, get_stablecoins and get_derivatives_overview need an API key; every other tool works without one.",
|
|
31
40
|
"",
|
|
32
41
|
"Data freshness: current funding rates refresh every 5 minutes; futures datasets refresh every 10 minutes to 6 hours depending on the metric; narrative/ecosystem market data refreshes every 2 hours and mindshare every 12 hours.",
|
|
42
|
+
"An endpoint tool answers { data, pagination?, meta }: `data` as the API served it, `pagination` when it is one page (pass pagination.cursor back for the next), and `meta` with the answer's freshness (as_of, stale_after, freshness_status, runtime_status) and warnings whenever the API reports them: treat freshness_status `stale` or `unknown` and runtime_status `degraded` as caveats to state, not as current data. meta.truncated_fields names what was cut to fit your context window.",
|
|
33
43
|
].join("\n");
|
|
34
44
|
const COIN_PARAM_SCHEMA = {
|
|
35
45
|
coin: z.string().describe("Coin ticker (e.g. BTC, ETH, SOL)"),
|
|
36
46
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const typedArgs = args;
|
|
61
|
-
const raw = await callApi(apiPath, fallbackPath, prepareArgs ? prepareArgs(typedArgs) : typedArgs);
|
|
62
|
-
// Filter and truncate the rows, then reattach pagination (and any
|
|
63
|
-
// metadata beside the page) so continuation cursors survive to
|
|
64
|
-
// the tool output.
|
|
65
|
-
const { rows, pagination, extras } = splitPaginated(raw);
|
|
66
|
-
const filtered = postProcess
|
|
67
|
-
? postProcess(rows, typedArgs, { paginated: pagination !== null })
|
|
68
|
-
: rows;
|
|
69
|
-
const truncated = truncateResponse(filtered);
|
|
70
|
-
return toToolResult(pagination
|
|
71
|
-
? { ...extras, data: truncated, pagination }
|
|
72
|
-
: truncated);
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
return toToolErrorResult(err);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
server.registerTool(name, {
|
|
81
|
-
title: titleFromToolName(name),
|
|
82
|
-
description,
|
|
83
|
-
outputSchema: API_TOOL_OUTPUT_SCHEMA,
|
|
84
|
-
annotations: READ_ONLY_MARKET_DATA_TOOL_ANNOTATIONS,
|
|
85
|
-
}, async () => {
|
|
86
|
-
try {
|
|
87
|
-
const raw = await callApi(apiPath, fallbackPath, {});
|
|
88
|
-
const { rows, pagination, extras } = splitPaginated(raw);
|
|
89
|
-
const filtered = postProcess
|
|
90
|
-
? postProcess(rows, {}, { paginated: pagination !== null })
|
|
91
|
-
: rows;
|
|
92
|
-
const truncated = truncateResponse(filtered);
|
|
93
|
-
return toToolResult(pagination
|
|
94
|
-
? { ...extras, data: truncated, pagination }
|
|
95
|
-
: truncated);
|
|
96
|
-
}
|
|
97
|
-
catch (err) {
|
|
98
|
-
return toToolErrorResult(err);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
// ── Composite tools ──────────────────────────────────────────────────
|
|
104
|
-
server.registerTool("analyze_coin", {
|
|
47
|
+
const JSON_SCHEMA_DRAFT_7 = "http://json-schema.org/draft-07/schema#";
|
|
48
|
+
/** What a composite answers: its markdown report (and analyze_coin's coin). */
|
|
49
|
+
const COMPOSITE_OUTPUT_SCHEMA = {
|
|
50
|
+
type: "object",
|
|
51
|
+
properties: {
|
|
52
|
+
report: { type: "string", description: "Formatted markdown report." },
|
|
53
|
+
// analyze_coin returns the coin beside its report; leaving it out made SDK
|
|
54
|
+
// clients that validate output reject every analyze_coin result (-32602,
|
|
55
|
+
// 2026-09-26).
|
|
56
|
+
coin: { type: "string", description: "Coin the report covers." },
|
|
57
|
+
error: {
|
|
58
|
+
type: "string",
|
|
59
|
+
description: "Error message when the call fails.",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
$schema: JSON_SCHEMA_DRAFT_7,
|
|
64
|
+
};
|
|
65
|
+
/** The composite tools: several endpoints, one markdown report (U13 serves them as endpoints). */
|
|
66
|
+
export const COMPOSITE_TOOLS = [
|
|
67
|
+
{
|
|
68
|
+
name: "analyze_coin",
|
|
105
69
|
title: "Analyze Coin",
|
|
106
70
|
description: "Single-coin analysis in one view: funding rates, futures OI, and a deterministic directional score.",
|
|
107
|
-
inputSchema:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
71
|
+
inputSchema: {
|
|
72
|
+
type: "object",
|
|
73
|
+
properties: {
|
|
74
|
+
coin: {
|
|
75
|
+
type: "string",
|
|
76
|
+
description: "Coin ticker (e.g. BTC, ETH, SOL)",
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
required: ["coin"],
|
|
80
|
+
additionalProperties: false,
|
|
81
|
+
$schema: JSON_SCHEMA_DRAFT_7,
|
|
82
|
+
},
|
|
83
|
+
run: async (callApi, args) => {
|
|
112
84
|
const coin = typeof args.coin === "string" ? args.coin : "BTC";
|
|
113
85
|
const text = await analyzeCoin(callApi, coin);
|
|
114
86
|
return toTextToolResult(text, { coin: coin.toUpperCase() });
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
server.registerTool("market_briefing", {
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "market_briefing",
|
|
121
91
|
title: "Market Briefing",
|
|
122
92
|
description: "Market briefing with market overview, top narratives, and a funding rate summary.",
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return toTextToolResult(text);
|
|
129
|
-
}
|
|
130
|
-
catch (err) {
|
|
131
|
-
return toToolErrorResult(err);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
server.registerTool("find_opportunities", {
|
|
93
|
+
inputSchema: { type: "object", properties: {} },
|
|
94
|
+
run: async (callApi) => toTextToolResult(await marketBriefing(callApi)),
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "find_opportunities",
|
|
135
98
|
title: "Find Opportunities",
|
|
136
99
|
description: "Scan all exchanges for the best funding rate arbitrage opportunities across spot-perp basis trades and cross-exchange funding arb.",
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
100
|
+
inputSchema: { type: "object", properties: {} },
|
|
101
|
+
run: async (callApi) => toTextToolResult(await findOpportunities(callApi)),
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
const EXECUTION = { taskSupport: "forbidden" };
|
|
105
|
+
/** tools/list: the endpoint tools as the manifest renders them, then the composites. */
|
|
106
|
+
export function listTools() {
|
|
107
|
+
return [
|
|
108
|
+
...ENDPOINT_TOOLS.map((tool) => ({
|
|
109
|
+
name: tool.name,
|
|
110
|
+
title: tool.title,
|
|
111
|
+
description: tool.description,
|
|
112
|
+
inputSchema: tool.input_schema,
|
|
113
|
+
// Published only when the manifest says so (PUBLISH_OUTPUT_SCHEMAS in scripts/contracts/agent-manifest.ts):
|
|
114
|
+
// a validating client fails a result that breaks its schema, and v1's are not proven yet.
|
|
115
|
+
...(MANIFEST.publish_output_schemas
|
|
116
|
+
? { outputSchema: tool.output_schema }
|
|
117
|
+
: {}),
|
|
118
|
+
annotations: READ_ONLY_MARKET_DATA_TOOL_ANNOTATIONS,
|
|
119
|
+
execution: EXECUTION,
|
|
120
|
+
})),
|
|
121
|
+
...COMPOSITE_TOOLS.map((tool) => ({
|
|
122
|
+
name: tool.name,
|
|
123
|
+
title: tool.title,
|
|
124
|
+
description: tool.description,
|
|
125
|
+
inputSchema: tool.inputSchema,
|
|
126
|
+
outputSchema: COMPOSITE_OUTPUT_SCHEMA,
|
|
127
|
+
annotations: READ_ONLY_MARKET_DATA_TOOL_ANNOTATIONS,
|
|
128
|
+
execution: EXECUTION,
|
|
129
|
+
})),
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
function compositeInputIssues(tool, args) {
|
|
133
|
+
const properties = (tool.inputSchema.properties ?? {});
|
|
134
|
+
const required = tool.inputSchema.required ?? [];
|
|
135
|
+
const issues = Object.keys(args)
|
|
136
|
+
.filter((name) => !(name in properties))
|
|
137
|
+
.map((name) => `unknown argument "${name}"`);
|
|
138
|
+
for (const [name, schema] of Object.entries(properties)) {
|
|
139
|
+
const value = args[name];
|
|
140
|
+
if (value === undefined || value === null) {
|
|
141
|
+
if (required.includes(name))
|
|
142
|
+
issues.push(`"${name}" is required`);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const issue = propertyIssue(name, value, schema);
|
|
146
|
+
if (issue !== null)
|
|
147
|
+
issues.push(issue);
|
|
148
|
+
}
|
|
149
|
+
return issues;
|
|
150
|
+
}
|
|
151
|
+
export function createSharpeMcpServer(options) {
|
|
152
|
+
const { callApi } = options;
|
|
153
|
+
const server = new McpServer({ name: "sharpe-mcp-server", version: options.version }, { instructions: SERVER_INSTRUCTIONS });
|
|
154
|
+
// ── Tools ─────────────────────────────────────────────────────────────
|
|
155
|
+
// Served from the manifest, so the JSON a client receives is the manifest's,
|
|
156
|
+
// not a re-rendering of it.
|
|
157
|
+
const endpointTools = new Map(ENDPOINT_TOOLS.map((tool) => [tool.name, tool]));
|
|
158
|
+
const compositeTools = new Map(COMPOSITE_TOOLS.map((tool) => [tool.name, tool]));
|
|
159
|
+
const tools = listTools();
|
|
160
|
+
server.server.registerCapabilities({ tools: { listChanged: true } });
|
|
161
|
+
server.server.setRequestHandler(ListToolsRequestSchema, () => ({ tools }));
|
|
162
|
+
server.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
163
|
+
const { name } = request.params;
|
|
164
|
+
const args = (request.params.arguments ?? {});
|
|
165
|
+
const endpointTool = endpointTools.get(name);
|
|
166
|
+
if (endpointTool !== undefined) {
|
|
167
|
+
try {
|
|
168
|
+
const result = await callEndpointTool(endpointTool, args, callApi);
|
|
169
|
+
return toStructuredToolResult(result);
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
return toTextErrorResult(err);
|
|
173
|
+
}
|
|
143
174
|
}
|
|
144
|
-
|
|
145
|
-
|
|
175
|
+
const composite = compositeTools.get(name);
|
|
176
|
+
if (composite !== undefined) {
|
|
177
|
+
const issues = compositeInputIssues(composite, args);
|
|
178
|
+
if (issues.length > 0) {
|
|
179
|
+
return toToolErrorResult(new Error(`Invalid arguments for ${name}: ${issues.join("; ")}`));
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
return await composite.run(callApi, args);
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
return toToolErrorResult(err);
|
|
186
|
+
}
|
|
146
187
|
}
|
|
188
|
+
return toTextErrorResult(new Error(`Tool ${name} not found`));
|
|
147
189
|
});
|
|
148
190
|
// ── Resources ─────────────────────────────────────────────────────────
|
|
149
191
|
server.registerResource("futures-charts", "sharpe://charts/futures", {
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GAGvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,cAAc,EACd,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,cAAc,EACd,cAAc,EACd,eAAe,EACf,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,sCAAsC,EACtC,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAS3B,uEAAuE;AACvE,MAAM,mBAAmB,GAAG;IAC1B,iLAAiL;IACjL,EAAE;IACF,oBAAoB;IACpB,2CAA2C;IAC3C,0EAA0E;IAC1E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,mCAAmC,IAAI,CAAC,WAAW,EAAE,yBAAyB;4BAC9E,yBAAyB;4BACzB,mDAAmD,IAAI,CAAC,WAAW,EAAE,gCAAgC;4BACrG,mDAAmD,IAAI,CAAC,WAAW,EAAE,uBAAuB;4BAC5F,+CAA+C;4BAC/C,uCAAuC;4BACvC,oCAAoC;4BACpC,kDAAkD;4BAClD,+FAA+F;4BAC/F,yEAAyE,IAAI,CAAC,WAAW,EAAE,eAAe;4BAC1G,+EAA+E;4BAC/E,0DAA0D,IAAI,CAAC,WAAW,EAAE,4CAA4C;4BACxH,qHAAqH;4BACrH,sCAAsC;4BACtC,yBAAyB,IAAI,CAAC,WAAW,EAAE,8BAA8B;4BACzE,mEAAmE;4BACnE,2EAA2E;4BAC3E,8DAA8D;4BAC9D,4FAA4F;qBAC/F;iBACF;aACF;SACF,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/tool-runtime.d.ts
CHANGED
|
@@ -3,59 +3,45 @@ import type { ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-com
|
|
|
3
3
|
export declare const MAX_ITEMS = 200;
|
|
4
4
|
export declare const CHARACTER_LIMIT = 25000;
|
|
5
5
|
export declare const READ_ONLY_MARKET_DATA_TOOL_ANNOTATIONS: ToolAnnotations;
|
|
6
|
-
export declare const API_TOOL_OUTPUT_SCHEMA: ZodRawShapeCompat;
|
|
7
6
|
/**
|
|
8
|
-
* Splits a
|
|
9
|
-
* the pagination envelope
|
|
10
|
-
* gem-finder/data);
|
|
11
|
-
*
|
|
12
|
-
* the cursor onward. Metadata riding beside a page (a futures chart's
|
|
13
|
-
* `chart`/`coverage`/`source`) comes back as `extras` so it is reattached
|
|
14
|
-
* too rather than dropped with the envelope.
|
|
7
|
+
* Splits a composite's API answer into rows + pagination. The api-client keeps
|
|
8
|
+
* the pagination envelope of paginated endpoints (funding/rates,
|
|
9
|
+
* gem-finder/data); metadata riding beside a page (a futures chart's
|
|
10
|
+
* `chart`/`coverage`/`source`) comes back as `extras`.
|
|
15
11
|
*/
|
|
16
12
|
export declare function splitPaginated(result: unknown): {
|
|
17
13
|
rows: unknown;
|
|
18
14
|
pagination: unknown | null;
|
|
19
15
|
extras: Record<string, unknown>;
|
|
20
16
|
};
|
|
21
|
-
/**
|
|
22
|
-
* Client-side paging for a free route that ignores limit/cursor and returns
|
|
23
|
-
* every row. Mirrors the v1 `paginateData` contract (src/lib/api/response.ts):
|
|
24
|
-
* the cursor is the base64url-encoded next offset, so a keyless caller walks
|
|
25
|
-
* the same pages an authenticated one would.
|
|
26
|
-
*/
|
|
27
|
-
export declare function paginateRows(rows: unknown[], limit: number, cursor?: string): {
|
|
28
|
-
data: unknown[];
|
|
29
|
-
pagination: {
|
|
30
|
-
cursor: string | null;
|
|
31
|
-
has_more: boolean;
|
|
32
|
-
total: number;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
17
|
/**
|
|
36
18
|
* A row's time in epoch ms, read from the keys the futures routes sort on
|
|
37
19
|
* (`snapshot_at ?? settled_at ?? timestamp`). Null when absent or unparseable.
|
|
38
20
|
*/
|
|
39
21
|
export declare function rowTimeMs(row: unknown): number | null;
|
|
40
|
-
export declare const
|
|
22
|
+
export declare const TRUNCATION_MESSAGE = "Response truncated to protect the agent context window. Narrow the result set with a cursor, offset, or filter parameters to retrieve the remaining items.";
|
|
23
|
+
/** One cut the client made: `total` items (or characters) received, `showing` kept. */
|
|
24
|
+
export interface TruncatedField {
|
|
25
|
+
total: number;
|
|
26
|
+
showing: number;
|
|
27
|
+
kept?: "latest";
|
|
28
|
+
}
|
|
29
|
+
/** The JSON text an agent receives, and the length the context guard measures (UTF-16 units, as Python counts them). */
|
|
30
|
+
export declare function jsonText(value: unknown): string;
|
|
41
31
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
32
|
+
* The payload cut to fit the agent's context window, and the cuts: every array to MAX_ITEMS, then, while the JSON
|
|
33
|
+
* is over CHARACTER_LIMIT, the largest array halved (an ascending series from its old end), then the longest string.
|
|
34
|
+
* The payload keeps its shape (the tool's output schema still holds); what was cut is reported beside it, by path
|
|
35
|
+
* from `data`, never inside it.
|
|
45
36
|
*/
|
|
46
|
-
export declare function
|
|
47
|
-
data: unknown
|
|
48
|
-
|
|
49
|
-
cursor: string | null;
|
|
50
|
-
has_more: boolean;
|
|
51
|
-
total: number;
|
|
52
|
-
};
|
|
37
|
+
export declare function capToContext(data: unknown): {
|
|
38
|
+
data: unknown;
|
|
39
|
+
fields: Record<string, TruncatedField>;
|
|
53
40
|
};
|
|
54
|
-
export declare
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
41
|
+
export declare const TEXT_TOOL_OUTPUT_SCHEMA: ZodRawShapeCompat;
|
|
42
|
+
/** An endpoint tool's answer: the result as `structuredContent`, and the same JSON as text for clients without it. */
|
|
43
|
+
export declare function toStructuredToolResult(result: Record<string, unknown>): {
|
|
44
|
+
structuredContent: Record<string, unknown>;
|
|
59
45
|
content: {
|
|
60
46
|
type: "text";
|
|
61
47
|
text: string;
|
|
@@ -70,6 +56,7 @@ export declare function toTextToolResult(report: string, extra?: Record<string,
|
|
|
70
56
|
text: string;
|
|
71
57
|
}[];
|
|
72
58
|
};
|
|
59
|
+
/** A composite's failure: `{ error }` as structured content, and as text. */
|
|
73
60
|
export declare function toToolErrorResult(error: unknown): {
|
|
74
61
|
structuredContent: {
|
|
75
62
|
error: string;
|
|
@@ -80,4 +67,12 @@ export declare function toToolErrorResult(error: unknown): {
|
|
|
80
67
|
}[];
|
|
81
68
|
isError: true;
|
|
82
69
|
};
|
|
70
|
+
/** An endpoint tool's failure: the message, as text (the Python server reports a tool error the same way). */
|
|
71
|
+
export declare function toTextErrorResult(error: unknown): {
|
|
72
|
+
content: {
|
|
73
|
+
type: "text";
|
|
74
|
+
text: string;
|
|
75
|
+
}[];
|
|
76
|
+
isError: true;
|
|
77
|
+
};
|
|
83
78
|
//# sourceMappingURL=tool-runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-runtime.d.ts","sourceRoot":"","sources":["../src/tool-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AAGxF,eAAO,MAAM,SAAS,MAAM,CAAC;AAC7B,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC,eAAO,MAAM,sCAAsC,EAAE,eAKpD,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"tool-runtime.d.ts","sourceRoot":"","sources":["../src/tool-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AAGxF,eAAO,MAAM,SAAS,MAAM,CAAC;AAC7B,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC,eAAO,MAAM,sCAAsC,EAAE,eAKpD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG;IAC/C,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,CAYA;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAOrD;AAwBD,eAAO,MAAM,kBAAkB,+JAC+H,CAAC;AAE/J,uFAAuF;AACvF,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB;AAED,wHAAwH;AACxH,wBAAgB,QAAQ,CAAC,KAAK,E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