@spotdowntime/mcp 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +41 -2
- package/index.d.ts +24 -0
- package/index.js +117 -0
- package/package.json +35 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Qikdrive Technologies Pvt Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @spotdowntime/mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
See how your MCP server's tools behave for real users: calls, error rate and latency per tool, with an alert when a tool starts failing. It works with servers built on the official TypeScript SDK, [`@modelcontextprotocol/sdk`](https://www.npmjs.com/package/@modelcontextprotocol/sdk).
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @spotdowntime/mcp
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
|
+
import { instrument } from "@spotdowntime/mcp";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
14
|
+
const server = new McpServer({ name: "docs", version: "1.0.0" });
|
|
15
|
+
instrument(server); // reads SPOTDOWNTIME_MCP_KEY
|
|
16
|
+
|
|
17
|
+
server.tool("search_docs", { query: z.string() }, async ({ query }) => { /* … */ });
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Get the key from your MCP server monitor's page in Spot Downtime (**Tool calls → Set up**), and set it as `SPOTDOWNTIME_MCP_KEY` where the server runs. Calls show up on the monitor's page within a minute.
|
|
21
|
+
|
|
22
|
+
## What's sent
|
|
23
|
+
|
|
24
|
+
For each `tools/call`: the tool's name, how long it took in milliseconds, and whether it worked. A call fails when the tool throws or returns `isError: true`.
|
|
25
|
+
|
|
26
|
+
Nothing else: no arguments, results, error messages, session IDs or anything about who called. Calls are sent in batches every 10 seconds from your server, never from your users.
|
|
27
|
+
|
|
28
|
+
## Options
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
const reporter = instrument(server, {
|
|
32
|
+
key: "mcpk_…", // default: process.env.SPOTDOWNTIME_MCP_KEY
|
|
33
|
+
flushIntervalMs: 10_000, // how often batches are sent
|
|
34
|
+
onError: (err) => {}, // a batch couldn't be sent (it's dropped); default: one console warning
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
await reporter.stop(); // on shutdown: sends what's left
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Reporting never throws into your server and never delays a tool call. If Spot Downtime can't be reached, batches are dropped.
|
|
41
|
+
|
|
42
|
+
Works with `McpServer` and the low-level `Server`, whether you call `instrument` before or after registering tools. Node 18 or later.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface InstrumentOptions {
|
|
2
|
+
/** The MCP monitor's ingest key (mcpk_…). Defaults to the SPOTDOWNTIME_MCP_KEY environment variable. */
|
|
3
|
+
key?: string;
|
|
4
|
+
/** Where batches go. Defaults to https://spotdowntime.com/api/v1/mcp/calls. */
|
|
5
|
+
endpoint?: string;
|
|
6
|
+
/** How often to send what's been recorded, in milliseconds. Defaults to 10 seconds. */
|
|
7
|
+
flushIntervalMs?: number;
|
|
8
|
+
/** Send early once this many calls are waiting (at most 1000). Defaults to 500. */
|
|
9
|
+
maxBatch?: number;
|
|
10
|
+
/** A fetch to send with, for tests or proxies. Defaults to the global fetch. */
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
/** Called when a batch can't be sent; it's dropped. Defaults to one console warning. */
|
|
13
|
+
onError?: (err: unknown) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Reporter {
|
|
17
|
+
/** Sends what's been recorded now. */
|
|
18
|
+
flush(): Promise<void>;
|
|
19
|
+
/** Stops recording and sends what's left, e.g. on shutdown. */
|
|
20
|
+
stop(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Starts reporting every tools/call of an McpServer (or low-level Server) to Spot Downtime. */
|
|
24
|
+
export function instrument(server: object, options?: InstrumentOptions): Reporter;
|
package/index.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Spot Downtime middleware for MCP servers built on the official TypeScript
|
|
2
|
+
// SDK (@modelcontextprotocol/sdk). It times every tools/call and sends
|
|
3
|
+
// batches of { tool, ms, ok } to Spot Downtime, where they show on the MCP
|
|
4
|
+
// monitor's page with per-tool error rates and latency, and can alert.
|
|
5
|
+
//
|
|
6
|
+
// Only the tool's name, how long it took and whether it worked are sent:
|
|
7
|
+
// never arguments, results, error messages or anything about the caller.
|
|
8
|
+
// Reporting never throws into your server and never slows a tool call down.
|
|
9
|
+
|
|
10
|
+
const DEFAULT_ENDPOINT = "https://spotdowntime.com/api/v1/mcp/calls";
|
|
11
|
+
const WRAPPED = Symbol.for("spotdowntime.mcp.wrapped");
|
|
12
|
+
const MAX_QUEUE = 10_000;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Starts reporting tool calls for an McpServer, or a low-level Server.
|
|
16
|
+
* Call it once, before or after registering tools.
|
|
17
|
+
*
|
|
18
|
+
* @param {object} server - an McpServer or a Server from @modelcontextprotocol/sdk
|
|
19
|
+
* @param {import("./index").InstrumentOptions} [options]
|
|
20
|
+
* @returns {import("./index").Reporter}
|
|
21
|
+
*/
|
|
22
|
+
export function instrument(server, options = {}) {
|
|
23
|
+
const key = options.key ?? globalThis.process?.env?.SPOTDOWNTIME_MCP_KEY;
|
|
24
|
+
if (!key) throw new Error("@spotdowntime/mcp: pass { key } or set SPOTDOWNTIME_MCP_KEY (copy it from the MCP monitor's page)");
|
|
25
|
+
const low = server?.server ?? server; // McpServer keeps the low-level Server in .server
|
|
26
|
+
const handlers = low?._requestHandlers;
|
|
27
|
+
if (!(handlers instanceof Map)) {
|
|
28
|
+
throw new Error("@spotdowntime/mcp: this doesn't look like an MCP server from @modelcontextprotocol/sdk 1.x");
|
|
29
|
+
}
|
|
30
|
+
const reporter = createReporter(key, options);
|
|
31
|
+
|
|
32
|
+
const wrap = (handler) => {
|
|
33
|
+
if (typeof handler !== "function" || handler[WRAPPED]) return handler;
|
|
34
|
+
const wrapped = async (request, extra) => {
|
|
35
|
+
const started = performance.now();
|
|
36
|
+
let ok = true;
|
|
37
|
+
try {
|
|
38
|
+
const result = await handler(request, extra);
|
|
39
|
+
if (result && result.isError) ok = false; // the tool reported a failure
|
|
40
|
+
return result;
|
|
41
|
+
} catch (err) {
|
|
42
|
+
ok = false;
|
|
43
|
+
throw err;
|
|
44
|
+
} finally {
|
|
45
|
+
reporter.record(request?.params?.name, performance.now() - started, ok);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
wrapped[WRAPPED] = true;
|
|
49
|
+
return wrapped;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// The SDK keeps one handler per method. Wrap tools/call now if it's there,
|
|
53
|
+
// and whenever it's set later (McpServer sets it with the first tool).
|
|
54
|
+
if (handlers.has("tools/call")) handlers.set("tools/call", wrap(handlers.get("tools/call")));
|
|
55
|
+
const set = handlers.set.bind(handlers);
|
|
56
|
+
handlers.set = (method, handler) => set(method, method === "tools/call" ? wrap(handler) : handler);
|
|
57
|
+
return reporter.public;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function createReporter(key, options) {
|
|
61
|
+
const endpoint = options.endpoint ?? DEFAULT_ENDPOINT;
|
|
62
|
+
const interval = options.flushIntervalMs ?? 10_000;
|
|
63
|
+
const maxBatch = Math.min(options.maxBatch ?? 500, 1000); // the API takes up to 1000
|
|
64
|
+
const send = options.fetch ?? globalThis.fetch;
|
|
65
|
+
const onError = options.onError ?? ((err) => warnOnce(`@spotdowntime/mcp: couldn't send tool calls: ${err.message ?? err}`));
|
|
66
|
+
let queue = [];
|
|
67
|
+
let inflight = Promise.resolve();
|
|
68
|
+
let stopped = false;
|
|
69
|
+
|
|
70
|
+
const flush = () => {
|
|
71
|
+
if (queue.length === 0) return inflight;
|
|
72
|
+
const batch = queue.splice(0, maxBatch);
|
|
73
|
+
inflight = inflight.then(async () => {
|
|
74
|
+
try {
|
|
75
|
+
const res = await send(endpoint, {
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
|
|
78
|
+
body: JSON.stringify({ calls: batch }),
|
|
79
|
+
});
|
|
80
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}${res.status === 401 ? ": check the ingest key" : ""}`);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
onError(err); // the batch is dropped: they're statistics
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return queue.length > 0 ? flush() : inflight;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const timer = setInterval(flush, interval);
|
|
89
|
+
timer.unref?.(); // don't keep the process alive just to report
|
|
90
|
+
const onExit = () => void flush();
|
|
91
|
+
globalThis.process?.once?.("beforeExit", onExit);
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
record(tool, ms, ok) {
|
|
95
|
+
if (stopped) return;
|
|
96
|
+
queue.push({ tool: typeof tool === "string" && tool ? tool : "(unknown)", ms: Math.round(ms * 10) / 10, ok });
|
|
97
|
+
if (queue.length > MAX_QUEUE) queue = queue.slice(-MAX_QUEUE); // the API is unreachable: keep the newest
|
|
98
|
+
if (queue.length >= maxBatch) void flush();
|
|
99
|
+
},
|
|
100
|
+
public: {
|
|
101
|
+
flush,
|
|
102
|
+
async stop() {
|
|
103
|
+
stopped = true;
|
|
104
|
+
clearInterval(timer);
|
|
105
|
+
globalThis.process?.off?.("beforeExit", onExit);
|
|
106
|
+
await flush();
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let warned = false;
|
|
113
|
+
function warnOnce(msg) {
|
|
114
|
+
if (warned) return;
|
|
115
|
+
warned = true;
|
|
116
|
+
console.warn(msg);
|
|
117
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spotdowntime/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Report your MCP server's tool calls to Spot Downtime: per-tool error rates, latency and alerts.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["index.js", "index.d.ts", "README.md", "LICENSE"],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "node --test"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@modelcontextprotocol/sdk": "^1.31.0"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"keywords": ["mcp", "model-context-protocol", "monitoring", "observability", "spot-downtime"],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"author": "Qikdrive Technologies Pvt Ltd",
|
|
30
|
+
"homepage": "https://spotdowntime.com",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/qikdrive/spotdowntime-mcp.git",
|
|
34
|
+
"directory": "mcp-js"
|
|
35
|
+
},
|
|
36
|
+
"bugs": "https://github.com/qikdrive/spotdowntime-mcp/issues"
|
|
37
|
+
}
|