@omnidim-ai/mcp-server 0.18.1 → 0.19.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 +6 -0
- package/build/docs-tools.d.ts +12 -0
- package/build/docs-tools.js +105 -0
- package/build/docs-tools.js.map +1 -0
- package/build/helpers.js +39 -7
- package/build/helpers.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +34 -16
- package/build/index.js.map +1 -1
- package/build/telemetry.d.ts +1 -0
- package/build/telemetry.js +12 -1
- package/build/telemetry.js.map +1 -1
- package/build/tool-annotations.d.ts +5 -0
- package/build/tool-annotations.js +19 -159
- package/build/tool-annotations.js.map +1 -1
- package/build/tool-marks.d.ts +2 -0
- package/build/tool-marks.js +621 -0
- package/build/tool-marks.js.map +1 -0
- package/package.json +2 -1
- package/src/docs-tools.ts +109 -0
- package/src/helpers.ts +39 -8
- package/src/index.ts +31 -15
- package/src/telemetry.ts +15 -1
- package/src/tool-annotations.ts +22 -162
- package/src/tool-marks.ts +623 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// searchDocs and readDoc: answers from the public docs at docs.omnidim.io, no account data.
|
|
2
|
+
// Same tools as the hosted server's app/services/docs.py.
|
|
3
|
+
import { USER_AGENT } from "./helpers.js";
|
|
4
|
+
|
|
5
|
+
const DOCS_ORIGIN = "https://docs.omnidim.io";
|
|
6
|
+
const MAX_DOC_CHARS = 25_000;
|
|
7
|
+
// One segment per path part: letters, digits, dash, underscore, dot (never a bare "." or "..").
|
|
8
|
+
const DOC_PATH_RE = /^\/docs(\/(?!\.{1,2}(\/|$))[A-Za-z0-9._-]+)*\/?$/;
|
|
9
|
+
|
|
10
|
+
const DOCS_TOOLS = [
|
|
11
|
+
{
|
|
12
|
+
name: "searchDocs",
|
|
13
|
+
description:
|
|
14
|
+
"Search the OmniDimension documentation (guides and API reference) at docs.omnidim.io. " +
|
|
15
|
+
"Use it before guessing how a feature, field or error works. Returns up to 8 pages, best first, " +
|
|
16
|
+
"each with title, description and url. Read a page with `readDoc`.\n\n(Tags: Docs)",
|
|
17
|
+
inputSchema: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: { query: { type: "string", description: "What to look for, in a few words." } },
|
|
20
|
+
required: ["query"],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "readDoc",
|
|
25
|
+
description:
|
|
26
|
+
"Read one docs.omnidim.io page as Markdown. Pass a `url` from `searchDocs`, or a path that " +
|
|
27
|
+
"starts with /docs/.\n\n(Tags: Docs)",
|
|
28
|
+
inputSchema: {
|
|
29
|
+
type: "object",
|
|
30
|
+
properties: {
|
|
31
|
+
url: {
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "A docs.omnidim.io page url or path, e.g. /docs/get-started/quickstart.",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
required: ["url"],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const NAMES = new Set(DOCS_TOOLS.map((t) => t.name));
|
|
42
|
+
|
|
43
|
+
export function isDocsTool(name: string): boolean {
|
|
44
|
+
return NAMES.has(name);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function addDocsTools(map: Map<string, any>): void {
|
|
48
|
+
for (const t of DOCS_TOOLS) {
|
|
49
|
+
map.set(t.name, { ...t, method: "get", pathTemplate: "", executionParameters: [], securityRequirements: [] });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The /docs/ path of a docs.omnidim.io page url or path, or null for anything else.
|
|
54
|
+
export function docPath(raw: unknown): string | null {
|
|
55
|
+
if (typeof raw !== "string") return null;
|
|
56
|
+
const trimmed = raw.trim();
|
|
57
|
+
// A full url must be exactly this origin; anything left must then be a /docs/ path.
|
|
58
|
+
const full = /^https:\/\/docs\.omnidim\.io(\/.*)?$/s.exec(trimmed);
|
|
59
|
+
const rest = full ? (full[1] ?? "") : trimmed;
|
|
60
|
+
let path: string;
|
|
61
|
+
try {
|
|
62
|
+
path = decodeURIComponent(rest.split(/[?#]/)[0]);
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
// The docs site redirects a trailing slash; asking for the final url saves a round trip.
|
|
67
|
+
return DOC_PATH_RE.test(path) ? path.replace(/\/+$/, "") || "/docs" : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type Result = { content: Array<{ type: "text"; text: string }>; isError?: boolean };
|
|
71
|
+
|
|
72
|
+
const ok = (text: string): Result => ({ content: [{ type: "text", text }] });
|
|
73
|
+
const fail = (text: string): Result => ({ content: [{ type: "text", text: JSON.stringify({ error: text }) }], isError: true });
|
|
74
|
+
|
|
75
|
+
function upstreamError(status: number): Result {
|
|
76
|
+
return fail(status === 429 ? "The docs search is busy. Wait a minute, then try again." : `docs.omnidim.io answered ${status}. Try again later.`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function get(fetchImpl: typeof fetch, url: string, headers: Record<string, string> = {}): Promise<Response> {
|
|
80
|
+
// The user's API key never goes to the docs site: these requests carry no Authorization.
|
|
81
|
+
return fetchImpl(url, { headers: { "User-Agent": USER_AGENT, ...headers }, signal: AbortSignal.timeout(15_000) });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function callDocsTool(name: string, args: Record<string, unknown>, fetchImpl: typeof fetch = fetch): Promise<Result> {
|
|
85
|
+
try {
|
|
86
|
+
if (name === "searchDocs") {
|
|
87
|
+
const query = typeof args.query === "string" ? args.query.trim().slice(0, 200) : "";
|
|
88
|
+
if (!query) return fail("searchDocs needs a query.");
|
|
89
|
+
// /api/spotlight ranks pages the way the docs site's own search and chat do.
|
|
90
|
+
const res = await get(fetchImpl, `${DOCS_ORIGIN}/api/spotlight?${new URLSearchParams({ q: query })}`);
|
|
91
|
+
if (res.status !== 200) return upstreamError(res.status);
|
|
92
|
+
const hits = (await res.json()) as Array<{ url?: unknown; title?: unknown; description?: unknown }>;
|
|
93
|
+
const pages = hits
|
|
94
|
+
.filter((h) => typeof h?.url === "string" && h.url.startsWith("/"))
|
|
95
|
+
.map((h) => ({ title: h.title, description: h.description, url: DOCS_ORIGIN + h.url }));
|
|
96
|
+
return ok(JSON.stringify({ pages }, null, 2));
|
|
97
|
+
}
|
|
98
|
+
const path = docPath(args.url);
|
|
99
|
+
if (!path) return fail("readDoc reads only https://docs.omnidim.io pages under /docs/.");
|
|
100
|
+
const res = await get(fetchImpl, DOCS_ORIGIN + path, { Accept: "text/markdown" });
|
|
101
|
+
if (res.status === 404) return fail(`No docs page at ${path}.`);
|
|
102
|
+
if (res.status !== 200) return upstreamError(res.status);
|
|
103
|
+
let text = await res.text();
|
|
104
|
+
if (text.length > MAX_DOC_CHARS) text = `${text.slice(0, MAX_DOC_CHARS)}\n\n[Page cut at ${MAX_DOC_CHARS} of ${text.length} chars.]`;
|
|
105
|
+
return ok(text);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
return fail(`docs.omnidim.io could not be reached (${e instanceof Error ? e.name : "error"}). Try again later.`);
|
|
108
|
+
}
|
|
109
|
+
}
|
package/src/helpers.ts
CHANGED
|
@@ -144,15 +144,46 @@ export function findList(data: unknown): { arr: unknown[]; key: string | null }
|
|
|
144
144
|
return null;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
//
|
|
148
|
-
|
|
147
|
+
// Call logs without their per-turn `interactions`, which are most of a call log's size.
|
|
148
|
+
function withoutTurnDetail(data: unknown): unknown | null {
|
|
149
|
+
const list = findList(data);
|
|
150
|
+
const rows = list ? list.arr : [data];
|
|
151
|
+
if (!rows.some((r) => r && typeof r === "object" && "interactions" in r)) return null;
|
|
152
|
+
const slim = rows.map((r) => {
|
|
153
|
+
if (!r || typeof r !== "object") return r;
|
|
154
|
+
const { interactions: _dropped, ...rest } = r as Record<string, unknown>;
|
|
155
|
+
return rest;
|
|
156
|
+
});
|
|
157
|
+
if (!list) return slim[0];
|
|
158
|
+
return list.key ? { ...(data as Record<string, unknown>), [list.key]: slim } : slim;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Trim responses to fit a model context budget: call log turn detail first, then
|
|
162
|
+
// list rows. Other single resources are never trimmed; an oversized getAgent etc.
|
|
149
163
|
// is handled by the MCP client (spill-to-file + chunked read).
|
|
164
|
+
|
|
150
165
|
export function trimLargeResponse(data: unknown): { text: string; note?: string } {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
166
|
+
let redacted = redactSensitive(data);
|
|
167
|
+
let full = JSON.stringify(redacted, null, 2);
|
|
168
|
+
if (full.length <= MAX_LIST_CHARS) return { text: full };
|
|
169
|
+
|
|
170
|
+
// Turn detail goes before rows or a cut, so transcript, recording and cost always arrive.
|
|
171
|
+
const slim = withoutTurnDetail(redacted);
|
|
172
|
+
const dropNote = slim !== null ? " Left out per-turn detail (interactions)." : "";
|
|
173
|
+
if (slim !== null) {
|
|
174
|
+
const slimText = JSON.stringify(slim, null, 2);
|
|
175
|
+
if (slimText.length <= MAX_LIST_CHARS) {
|
|
176
|
+
return {
|
|
177
|
+
text: slimText,
|
|
178
|
+
note: "[Left out per-turn detail (interactions) to fit. call_conversation has the transcript.]",
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
redacted = slim;
|
|
182
|
+
full = slimText;
|
|
183
|
+
}
|
|
154
184
|
|
|
155
|
-
|
|
185
|
+
const list = findList(redacted);
|
|
186
|
+
if (!list) return { text: full };
|
|
156
187
|
|
|
157
188
|
const { arr, key } = list;
|
|
158
189
|
let kept = arr.length;
|
|
@@ -164,7 +195,7 @@ export function trimLargeResponse(data: unknown): { text: string; note?: string
|
|
|
164
195
|
if (candidate.length <= MAX_LIST_CHARS) {
|
|
165
196
|
return {
|
|
166
197
|
text: candidate,
|
|
167
|
-
note: `[Showing ${kept} of ${arr.length} items
|
|
198
|
+
note: `[Showing ${kept} of ${arr.length} items.${dropNote} Lower pagesize, filter by name, or fetch a specific item by ID for full detail.]`,
|
|
168
199
|
};
|
|
169
200
|
}
|
|
170
201
|
kept = Math.max(1, Math.floor(kept * 0.6));
|
|
@@ -172,7 +203,7 @@ export function trimLargeResponse(data: unknown): { text: string; note?: string
|
|
|
172
203
|
|
|
173
204
|
return {
|
|
174
205
|
text: full.slice(0, MAX_LIST_CHARS),
|
|
175
|
-
note: `[Response truncated. Full size: ${full.length} chars
|
|
206
|
+
note: `[Response truncated. Full size: ${full.length} chars.${dropNote}]`,
|
|
176
207
|
};
|
|
177
208
|
}
|
|
178
209
|
|