@pmxt/mcp 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/dist/args.d.ts +16 -0
- package/dist/args.js +42 -0
- package/dist/client.d.ts +15 -0
- package/dist/client.js +36 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +24 -0
- package/dist/generated/tools.d.ts +15 -0
- package/dist/generated/tools.js +1890 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +16 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +93 -0
- package/package.json +39 -0
package/dist/args.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reconstruct the positional args array from flat MCP tool input.
|
|
3
|
+
*
|
|
4
|
+
* MCP tools receive a flat { key: value } object. The PMXT REST API
|
|
5
|
+
* expects a positional args array: POST body { args: [...] }.
|
|
6
|
+
*
|
|
7
|
+
* This module bridges the two using the ArgSpec metadata embedded in
|
|
8
|
+
* each generated tool definition.
|
|
9
|
+
*/
|
|
10
|
+
import type { ArgSpec } from "./generated/tools.js";
|
|
11
|
+
/**
|
|
12
|
+
* Given a flat input object (with exchange and credentials already
|
|
13
|
+
* removed) and the arg spec for the method, produce the positional
|
|
14
|
+
* args array the sidecar expects.
|
|
15
|
+
*/
|
|
16
|
+
export declare function reconstructArgs(input: Record<string, unknown>, argSpec: readonly ArgSpec[]): unknown[];
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reconstruct the positional args array from flat MCP tool input.
|
|
3
|
+
*
|
|
4
|
+
* MCP tools receive a flat { key: value } object. The PMXT REST API
|
|
5
|
+
* expects a positional args array: POST body { args: [...] }.
|
|
6
|
+
*
|
|
7
|
+
* This module bridges the two using the ArgSpec metadata embedded in
|
|
8
|
+
* each generated tool definition.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Given a flat input object (with exchange and credentials already
|
|
12
|
+
* removed) and the arg spec for the method, produce the positional
|
|
13
|
+
* args array the sidecar expects.
|
|
14
|
+
*/
|
|
15
|
+
export function reconstructArgs(input, argSpec) {
|
|
16
|
+
const args = [];
|
|
17
|
+
// Names of non-flattened args so we can exclude them when collecting
|
|
18
|
+
// properties for a flattened object arg.
|
|
19
|
+
const namedArgs = new Set(argSpec.filter((s) => !s.flatten).map((s) => s.name));
|
|
20
|
+
for (const spec of argSpec) {
|
|
21
|
+
if (spec.flatten) {
|
|
22
|
+
// This arg's properties were spread into the top-level input.
|
|
23
|
+
// Collect everything that isn't a named primitive arg.
|
|
24
|
+
const obj = {};
|
|
25
|
+
for (const [key, value] of Object.entries(input)) {
|
|
26
|
+
if (!namedArgs.has(key) && value !== undefined) {
|
|
27
|
+
obj[key] = value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
args.push(Object.keys(obj).length > 0 ? obj : undefined);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const value = input[spec.name];
|
|
34
|
+
args.push(value !== undefined ? value : undefined);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Trim trailing undefineds so optional tail params stay optional.
|
|
38
|
+
while (args.length > 0 && args[args.length - 1] === undefined) {
|
|
39
|
+
args.pop();
|
|
40
|
+
}
|
|
41
|
+
return args;
|
|
42
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the PMXT REST API.
|
|
3
|
+
*
|
|
4
|
+
* Every MCP tool call becomes a POST to /api/{exchange}/{method} with
|
|
5
|
+
* the standard { args, credentials? } body shape. POST works for all
|
|
6
|
+
* endpoints (reads and writes) on both the hosted API and the sidecar.
|
|
7
|
+
*/
|
|
8
|
+
import type { Config } from "./config.js";
|
|
9
|
+
export interface CallOptions {
|
|
10
|
+
readonly exchange: string;
|
|
11
|
+
readonly method: string;
|
|
12
|
+
readonly args: unknown[];
|
|
13
|
+
readonly credentials?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export declare function callPmxtApi(config: Config, options: CallOptions): Promise<unknown>;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the PMXT REST API.
|
|
3
|
+
*
|
|
4
|
+
* Every MCP tool call becomes a POST to /api/{exchange}/{method} with
|
|
5
|
+
* the standard { args, credentials? } body shape. POST works for all
|
|
6
|
+
* endpoints (reads and writes) on both the hosted API and the sidecar.
|
|
7
|
+
*/
|
|
8
|
+
export async function callPmxtApi(config, options) {
|
|
9
|
+
const url = `${config.apiUrl}/api/${encodeURIComponent(options.exchange)}/${encodeURIComponent(options.method)}`;
|
|
10
|
+
const headers = {
|
|
11
|
+
"Content-Type": "application/json",
|
|
12
|
+
};
|
|
13
|
+
if (config.apiKey) {
|
|
14
|
+
headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
15
|
+
}
|
|
16
|
+
const body = { args: options.args };
|
|
17
|
+
if (options.credentials && Object.keys(options.credentials).length > 0) {
|
|
18
|
+
body.credentials = options.credentials;
|
|
19
|
+
}
|
|
20
|
+
const response = await fetch(url, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers,
|
|
23
|
+
body: JSON.stringify(body),
|
|
24
|
+
});
|
|
25
|
+
const json = (await response.json());
|
|
26
|
+
if (!response.ok || json.success === false) {
|
|
27
|
+
const err = json.error;
|
|
28
|
+
const message = typeof err === "string"
|
|
29
|
+
? err
|
|
30
|
+
: typeof err === "object" && err !== null
|
|
31
|
+
? err.message || JSON.stringify(err)
|
|
32
|
+
: response.statusText;
|
|
33
|
+
throw new Error(message);
|
|
34
|
+
}
|
|
35
|
+
return json.data;
|
|
36
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment-based configuration for the PMXT MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Precedence mirrors the SDK: PMXT_API_URL overrides everything,
|
|
5
|
+
* otherwise default to the hosted endpoint when an API key is present
|
|
6
|
+
* or localhost when running alongside the sidecar.
|
|
7
|
+
*/
|
|
8
|
+
export interface Config {
|
|
9
|
+
readonly apiUrl: string;
|
|
10
|
+
readonly apiKey: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare function loadConfig(): Config;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment-based configuration for the PMXT MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Precedence mirrors the SDK: PMXT_API_URL overrides everything,
|
|
5
|
+
* otherwise default to the hosted endpoint when an API key is present
|
|
6
|
+
* or localhost when running alongside the sidecar.
|
|
7
|
+
*/
|
|
8
|
+
const HOSTED_URL = "https://api.pmxt.dev";
|
|
9
|
+
const LOCAL_URL = "http://localhost:3847";
|
|
10
|
+
export function loadConfig() {
|
|
11
|
+
const apiKey = process.env.PMXT_API_KEY || undefined;
|
|
12
|
+
const explicit = process.env.PMXT_API_URL;
|
|
13
|
+
let apiUrl;
|
|
14
|
+
if (explicit) {
|
|
15
|
+
apiUrl = explicit;
|
|
16
|
+
}
|
|
17
|
+
else if (apiKey) {
|
|
18
|
+
apiUrl = HOSTED_URL;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
apiUrl = LOCAL_URL;
|
|
22
|
+
}
|
|
23
|
+
return Object.freeze({ apiUrl, apiKey });
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ArgSpec {
|
|
2
|
+
name: string;
|
|
3
|
+
kind: string;
|
|
4
|
+
optional: boolean;
|
|
5
|
+
flatten: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface ToolDef {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
inputSchema: Record<string, unknown>;
|
|
11
|
+
annotations: Record<string, boolean>;
|
|
12
|
+
method: string;
|
|
13
|
+
args: ArgSpec[];
|
|
14
|
+
}
|
|
15
|
+
export declare const TOOLS: ToolDef[];
|