@aveq-research/surfmeter-mcp 0.2.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 +127 -0
- package/build/client.d.ts +25 -0
- package/build/client.js +102 -0
- package/build/client.js.map +1 -0
- package/build/config.d.ts +7 -0
- package/build/config.js +46 -0
- package/build/config.js.map +1 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +17 -0
- package/build/index.js.map +1 -0
- package/build/result.d.ts +3 -0
- package/build/result.js +27 -0
- package/build/result.js.map +1 -0
- package/build/server.d.ts +3 -0
- package/build/server.js +14 -0
- package/build/server.js.map +1 -0
- package/build/tools.d.ts +3 -0
- package/build/tools.js +988 -0
- package/build/tools.js.map +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AVEQ GmbH
|
|
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
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Surfmeter MCP Server
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol server for the AVEQ Surfmeter management API. It exposes typed tools for clients, measurements, anomalies, groups, ISPs, users, keys, capabilities, settings, license usage, and the built-in AI assistant.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js 20 or newer
|
|
8
|
+
- A Surfmeter management API key beginning with `client_admin-`
|
|
9
|
+
- A reachable Surfmeter server
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Install the MCP server globally:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add --global @aveq-research/surfmeter-mcp
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Configuration
|
|
20
|
+
|
|
21
|
+
The server requires two environment variables:
|
|
22
|
+
|
|
23
|
+
- `API_ENDPOINT`: Either the Surfmeter server origin, such as `https://surfmeter-server.demo-analytics.aveq.info`, or the complete management endpoint, such as `https://surfmeter-server.demo-analytics.aveq.info/client_admin_api/v1`.
|
|
24
|
+
- `API_KEY`: A Surfmeter management API key. It is sent in the `X-API-KEY` request header.
|
|
25
|
+
- `API_TIMEOUT_MS`: Optional request timeout in milliseconds. The default is 30000.
|
|
26
|
+
|
|
27
|
+
Do not put a real key in source control. `.env` is ignored, but MCP clients should normally inject the values through their server configuration.
|
|
28
|
+
|
|
29
|
+
## MCP client configuration
|
|
30
|
+
|
|
31
|
+
Configure your MCP client to launch the installed `surfmeter-mcp` executable:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"mcpServers": {
|
|
36
|
+
"surfmeter": {
|
|
37
|
+
"command": "surfmeter-mcp",
|
|
38
|
+
"env": {
|
|
39
|
+
"API_ENDPOINT": "https://surfmeter-server.demo-analytics.aveq.info",
|
|
40
|
+
"API_KEY": "client_admin-replace-me"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Tool surface
|
|
48
|
+
|
|
49
|
+
The server advertises ten tools. Five common operations are promoted directly:
|
|
50
|
+
|
|
51
|
+
- `surfmeter_get_clients`: list clients or get one client
|
|
52
|
+
- `surfmeter_update_client`: update client labels, tags, or groups
|
|
53
|
+
- `surfmeter_search_measurements`: query and aggregate measurements
|
|
54
|
+
- `surfmeter_search_anomalies`: query and aggregate anomaly episodes
|
|
55
|
+
- `surfmeter_get_system_status`: read version, measurement options, license usage, or AI status
|
|
56
|
+
|
|
57
|
+
The complete management API remains available through a searchable internal action catalog:
|
|
58
|
+
|
|
59
|
+
- `surfmeter_search_actions`: find operations from a natural-language intent
|
|
60
|
+
- `surfmeter_describe_action`: retrieve one operation's exact parameter schema
|
|
61
|
+
- `surfmeter_execute_read_action`: execute discovered read-only operations
|
|
62
|
+
- `surfmeter_execute_write_action`: execute discovered non-destructive mutations
|
|
63
|
+
- `surfmeter_execute_destructive_action`: execute deletes, revocations, merges, and client disabling
|
|
64
|
+
|
|
65
|
+
For example:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"query": "create a registration key",
|
|
70
|
+
"category": "write"
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The result identifies the action, its parameter names, and the correct executor. Use `surfmeter_describe_action` when the exact schema is needed, then pass the selected action to that executor:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"action_id": "surfmeter_create_registration_key",
|
|
79
|
+
"params": {
|
|
80
|
+
"comment": "Video probes",
|
|
81
|
+
"capability_id": 12
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The server validates `params` against the selected action's internal Zod schema. It rejects action/executor category mismatches. Read, write, and destructive executors have separate MCP annotations so compatible hosts can apply the correct confirmation behavior.
|
|
87
|
+
|
|
88
|
+
The internal catalog covers clients, groups, ISP contracts, ISPs, users, API keys, registration keys, capabilities, measurements, anomalies, tuning overrides, settings, license usage, and Surfmeter's built-in AI assistant.
|
|
89
|
+
|
|
90
|
+
Magic-link and session endpoints are intentionally not exposed. They are browser authentication mechanisms and are neither needed nor appropriate when the MCP server already authenticates with a management API key.
|
|
91
|
+
|
|
92
|
+
## Elasticsearch searches
|
|
93
|
+
|
|
94
|
+
`surfmeter_search_measurements` and `surfmeter_search_anomalies` accept Elasticsearch Query DSL under `body`.
|
|
95
|
+
|
|
96
|
+
Use `.keyword` for exact matching, aggregations, and sorting on text fields:
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"body": {
|
|
101
|
+
"size": 0,
|
|
102
|
+
"query": {
|
|
103
|
+
"term": {
|
|
104
|
+
"type.keyword": "VideoMeasurement"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"aggs": {
|
|
108
|
+
"by_client": {
|
|
109
|
+
"terms": {
|
|
110
|
+
"field": "client_label.keyword"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The server parses normal JSON and Elasticsearch NDJSON scroll responses. Prefer server-side filtering and aggregation to downloading and filtering large datasets in the agent.
|
|
119
|
+
|
|
120
|
+
## Agent skill
|
|
121
|
+
|
|
122
|
+
The companion [Surfmeter skills repository](https://github.com/aveq-research/surfmeter-skills) teaches compatible coding agents how to invoke the API directly, and how to construct Elasticsearch requests.
|
|
123
|
+
Skills are orthogonal to MCP servers. You may choose to not load an MCP server's heavy tool definition in all sessions; skills are a good, lightweight alternative to that.
|
|
124
|
+
|
|
125
|
+
## Development
|
|
126
|
+
|
|
127
|
+
See [DEVELOPERS.md](DEVELOPERS.md) for contributor setup, build instructions, implementation notes, and testing.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SurfmeterConfig } from "./config.js";
|
|
2
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
3
|
+
export type QueryValue = string | number | boolean | null | undefined | readonly (string | number | boolean)[];
|
|
4
|
+
export interface ApiRequest {
|
|
5
|
+
method?: HttpMethod;
|
|
6
|
+
path: string;
|
|
7
|
+
query?: Record<string, QueryValue>;
|
|
8
|
+
body?: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface ApiResponse {
|
|
11
|
+
data: unknown;
|
|
12
|
+
contentType: string;
|
|
13
|
+
status: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class SurfmeterApiError extends Error {
|
|
16
|
+
readonly status: number;
|
|
17
|
+
readonly details: unknown;
|
|
18
|
+
constructor(status: number, message: string, details: unknown);
|
|
19
|
+
}
|
|
20
|
+
export declare class SurfmeterClient {
|
|
21
|
+
private readonly config;
|
|
22
|
+
private readonly fetchImpl;
|
|
23
|
+
constructor(config: SurfmeterConfig, fetchImpl?: typeof fetch);
|
|
24
|
+
request(request: ApiRequest): Promise<ApiResponse>;
|
|
25
|
+
}
|
package/build/client.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export class SurfmeterApiError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
details;
|
|
4
|
+
constructor(status, message, details) {
|
|
5
|
+
super(`Surfmeter API request failed (${status}): ${message}`);
|
|
6
|
+
this.name = "SurfmeterApiError";
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.details = details;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function addQuery(url, query) {
|
|
12
|
+
for (const [key, value] of Object.entries(query)) {
|
|
13
|
+
if (value === undefined || value === null) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
for (const entry of value) {
|
|
18
|
+
url.searchParams.append(key, String(entry));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
url.searchParams.set(key, String(value));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function messageFromError(data, fallback) {
|
|
27
|
+
if (typeof data === "object" && data !== null) {
|
|
28
|
+
const object = data;
|
|
29
|
+
for (const key of ["message", "error"]) {
|
|
30
|
+
if (typeof object[key] === "string" && object[key].length > 0) {
|
|
31
|
+
return object[key];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return fallback;
|
|
36
|
+
}
|
|
37
|
+
function parseNdjson(text) {
|
|
38
|
+
return text
|
|
39
|
+
.split(/\r?\n/)
|
|
40
|
+
.filter((line) => line.trim().length > 0)
|
|
41
|
+
.map((line) => JSON.parse(line));
|
|
42
|
+
}
|
|
43
|
+
async function parseResponse(response) {
|
|
44
|
+
if (response.status === 204) {
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
48
|
+
const text = await response.text();
|
|
49
|
+
if (text.length === 0) {
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
if (contentType.includes("application/x-ndjson")) {
|
|
53
|
+
return parseNdjson(text);
|
|
54
|
+
}
|
|
55
|
+
if (contentType.includes("json")) {
|
|
56
|
+
try {
|
|
57
|
+
return JSON.parse(text);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
throw new Error("Surfmeter API returned invalid JSON");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return text;
|
|
64
|
+
}
|
|
65
|
+
export class SurfmeterClient {
|
|
66
|
+
config;
|
|
67
|
+
fetchImpl;
|
|
68
|
+
constructor(config, fetchImpl = fetch) {
|
|
69
|
+
this.config = config;
|
|
70
|
+
this.fetchImpl = fetchImpl;
|
|
71
|
+
}
|
|
72
|
+
async request(request) {
|
|
73
|
+
const url = new URL(`${this.config.apiEndpoint}/${request.path.replace(/^\/+/, "")}`);
|
|
74
|
+
if (request.query) {
|
|
75
|
+
addQuery(url, request.query);
|
|
76
|
+
}
|
|
77
|
+
const method = request.method ?? "GET";
|
|
78
|
+
const body = request.body === undefined ? {} : { body: JSON.stringify(request.body) };
|
|
79
|
+
const response = await this.fetchImpl(url, {
|
|
80
|
+
method,
|
|
81
|
+
headers: {
|
|
82
|
+
Accept: "application/json, application/x-ndjson, text/plain",
|
|
83
|
+
"X-API-KEY": this.config.apiKey,
|
|
84
|
+
...(request.body === undefined
|
|
85
|
+
? {}
|
|
86
|
+
: { "Content-Type": "application/json" }),
|
|
87
|
+
},
|
|
88
|
+
...body,
|
|
89
|
+
signal: AbortSignal.timeout(this.config.timeoutMs),
|
|
90
|
+
});
|
|
91
|
+
const data = await parseResponse(response);
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
throw new SurfmeterApiError(response.status, messageFromError(data, response.statusText), data);
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
data,
|
|
97
|
+
contentType: response.headers.get("content-type") ?? "",
|
|
98
|
+
status: response.status,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAwBA,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,MAAM,CAAS;IACf,OAAO,CAAU;IAE1B,YAAY,MAAc,EAAE,OAAe,EAAE,OAAgB;QAC3D,KAAK,CAAC,iCAAiC,MAAM,MAAM,OAAO,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,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1,46 @@
|
|
|
1
|
+
const API_PATH = "/client_admin_api/v1";
|
|
2
|
+
export function normalizeApiEndpoint(value) {
|
|
3
|
+
let url;
|
|
4
|
+
try {
|
|
5
|
+
url = new URL(value);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
throw new Error("API_ENDPOINT must be an absolute HTTP(S) URL");
|
|
9
|
+
}
|
|
10
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
11
|
+
throw new Error("API_ENDPOINT must use http or https");
|
|
12
|
+
}
|
|
13
|
+
url.search = "";
|
|
14
|
+
url.hash = "";
|
|
15
|
+
url.pathname = url.pathname.replace(/\/+$/, "");
|
|
16
|
+
if (!url.pathname.endsWith(API_PATH)) {
|
|
17
|
+
url.pathname = `${url.pathname}${API_PATH}`.replace(/\/+/g, "/");
|
|
18
|
+
}
|
|
19
|
+
return url.toString().replace(/\/$/, "");
|
|
20
|
+
}
|
|
21
|
+
function parseTimeout(value) {
|
|
22
|
+
if (value === undefined) {
|
|
23
|
+
return 30_000;
|
|
24
|
+
}
|
|
25
|
+
const timeout = Number(value);
|
|
26
|
+
if (!Number.isInteger(timeout) || timeout < 1 || timeout > 300_000) {
|
|
27
|
+
throw new Error("API_TIMEOUT_MS must be an integer between 1 and 300000");
|
|
28
|
+
}
|
|
29
|
+
return timeout;
|
|
30
|
+
}
|
|
31
|
+
export function loadConfig(env = process.env) {
|
|
32
|
+
const endpoint = env.API_ENDPOINT?.trim();
|
|
33
|
+
const apiKey = env.API_KEY?.trim();
|
|
34
|
+
if (!endpoint) {
|
|
35
|
+
throw new Error("Missing required environment variable API_ENDPOINT");
|
|
36
|
+
}
|
|
37
|
+
if (!apiKey) {
|
|
38
|
+
throw new Error("Missing required environment variable API_KEY");
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
apiEndpoint: normalizeApiEndpoint(endpoint),
|
|
42
|
+
apiKey,
|
|
43
|
+
timeoutMs: parseTimeout(env.API_TIMEOUT_MS),
|
|
44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C9B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,OAAO,GAAG,OAAO,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,UAAU,CACxB,GAAG,GAAsB,OAAO,CAAC,GAAG;IAEpC,MAAM,QAAQ,GAAG,GAAG,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC;IAC1C,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;IAEnC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,OAAO;QACL,WAAW,EAAE,oBAAoB,CAAC,QAAQ,CAAC;QAC3C,MAAM;QACN,SAAS,EAAE,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC;KAC5C,CAAC;AACJ,CAAC"}
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { loadConfig } from "./config.js";
|
|
4
|
+
import { createServer } from "./server.js";
|
|
5
|
+
async function main() {
|
|
6
|
+
const config = loadConfig();
|
|
7
|
+
const server = createServer(config);
|
|
8
|
+
const transport = new StdioServerTransport();
|
|
9
|
+
await server.connect(transport);
|
|
10
|
+
console.error(`Surfmeter MCP server connected to ${config.apiEndpoint} over stdio`);
|
|
11
|
+
}
|
|
12
|
+
main().catch((error) => {
|
|
13
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
14
|
+
console.error(`Surfmeter MCP server failed: ${message}`);
|
|
15
|
+
process.exitCode = 1;
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CACX,qCAAqC,MAAM,CAAC,WAAW,aAAa,CACrE,CAAC;AACJ,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,CAAC,KAAK,CAAC,gCAAgC,OAAO,EAAE,CAAC,CAAC;IACzD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
|
package/build/result.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SurfmeterApiError } from "./client.js";
|
|
2
|
+
export function successResult(data) {
|
|
3
|
+
return {
|
|
4
|
+
content: [
|
|
5
|
+
{
|
|
6
|
+
type: "text",
|
|
7
|
+
text: typeof data === "string" ? data : JSON.stringify(data, null, 2),
|
|
8
|
+
},
|
|
9
|
+
],
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function errorResult(error) {
|
|
13
|
+
const message = error instanceof Error ? error.message : "Unknown Surfmeter MCP error";
|
|
14
|
+
const details = error instanceof SurfmeterApiError ? error.details : undefined;
|
|
15
|
+
return {
|
|
16
|
+
isError: true,
|
|
17
|
+
content: [
|
|
18
|
+
{
|
|
19
|
+
type: "text",
|
|
20
|
+
text: details === undefined
|
|
21
|
+
? message
|
|
22
|
+
: `${message}\n${JSON.stringify(details, null, 2)}`,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,UAAU,aAAa,CAAC,IAAa;IACzC,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAe;gBACrB,IAAI,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;aACtE;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,MAAM,OAAO,GACX,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC;IACzE,MAAM,OAAO,GACX,KAAK,YAAY,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAEjE,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAe;gBACrB,IAAI,EACF,OAAO,KAAK,SAAS;oBACnB,CAAC,CAAC,OAAO;oBACT,CAAC,CAAC,GAAG,OAAO,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;aACxD;SACF;KACF,CAAC;AACJ,CAAC"}
|
package/build/server.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { SurfmeterClient } from "./client.js";
|
|
3
|
+
import { registerSurfmeterTools } from "./tools.js";
|
|
4
|
+
export function createServer(config) {
|
|
5
|
+
const server = new McpServer({
|
|
6
|
+
name: "surfmeter",
|
|
7
|
+
version: "0.2.0",
|
|
8
|
+
}, {
|
|
9
|
+
instructions: "Use the promoted client, measurement, anomaly, and system-status tools directly. For every other operation, call surfmeter_search_actions, then use the executor named in its result. Call surfmeter_describe_action when the exact schema is needed. Never pass a write action to the read executor or a destructive action to the normal write executor. Confirm exact targets and consequences before calling surfmeter_execute_destructive_action. Elasticsearch exact text matches, aggregations, and sorts should use .keyword fields.",
|
|
10
|
+
});
|
|
11
|
+
registerSurfmeterTools(server, new SurfmeterClient(config));
|
|
12
|
+
return server;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,UAAU,YAAY,CAAC,MAAuB;IAClD,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B;QACE,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,OAAO;KACjB,EACD;QACE,YAAY,EACV,8gBAA8gB;KACjhB,CACF,CAAC;IAEF,sBAAsB,CAAC,MAAM,EAAE,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/build/tools.d.ts
ADDED