@cplace/mcp-server 2.0.0 → 2.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/README.md +31 -14
- package/dist/backend-capabilities.d.ts +10 -1
- package/dist/backend-capabilities.d.ts.map +1 -1
- package/dist/backend-capabilities.js +13 -0
- package/dist/backend-capabilities.js.map +1 -1
- package/dist/capability-gating.d.ts +7 -2
- package/dist/capability-gating.d.ts.map +1 -1
- package/dist/capability-gating.js +49 -8
- package/dist/capability-gating.js.map +1 -1
- package/dist/index.js +60 -40
- package/dist/index.js.map +1 -1
- package/dist/lint-on-write.d.ts +14 -0
- package/dist/lint-on-write.d.ts.map +1 -0
- package/dist/lint-on-write.js +29 -0
- package/dist/lint-on-write.js.map +1 -0
- package/dist/plugin-registry.d.ts +1 -1
- package/dist/plugin-registry.d.ts.map +1 -1
- package/dist/plugin-registry.js +28 -13
- package/dist/plugin-registry.js.map +1 -1
- package/dist/plugins/core/widget-specifications/cf.cplace.platform.tableWidget/search.md +10 -0
- package/dist/plugins/core/widget-specifications/cf.platform.connectedBarChart/search.md +6 -0
- package/dist/plugins/core/widget-specifications/cf.platform.connectedPieChart/search.md +6 -0
- package/dist/plugins/core/widget-specifications/cf.platform.embeddedSearchAsList/search.md +6 -0
- package/dist/plugins/core/widget-specifications/cf.platform.embeddedSearchAsTable/search.md +6 -0
- package/dist/plugins/low-code.d.ts.map +1 -1
- package/dist/plugins/low-code.js +5 -0
- package/dist/plugins/low-code.js.map +1 -1
- package/dist/searchConversion.d.ts +6 -0
- package/dist/searchConversion.d.ts.map +1 -1
- package/dist/searchConversion.js +219 -132
- package/dist/searchConversion.js.map +1 -1
- package/dist/searchEditorShape.d.ts +10 -0
- package/dist/searchEditorShape.d.ts.map +1 -0
- package/dist/searchEditorShape.js +103 -0
- package/dist/searchEditorShape.js.map +1 -0
- package/dist/searchSchema.d.ts +119 -119
- package/dist/searchSchema.d.ts.map +1 -1
- package/dist/searchSchema.js +102 -50
- package/dist/searchSchema.js.map +1 -1
- package/dist/session-responses.d.ts +23 -0
- package/dist/session-responses.d.ts.map +1 -0
- package/dist/session-responses.js +17 -0
- package/dist/session-responses.js.map +1 -0
- package/dist/strict-schemas.d.ts +8 -0
- package/dist/strict-schemas.d.ts.map +1 -0
- package/dist/strict-schemas.js +202 -0
- package/dist/strict-schemas.js.map +1 -0
- package/dist/tools/change-listeners.d.ts.map +1 -1
- package/dist/tools/change-listeners.js +19 -11
- package/dist/tools/change-listeners.js.map +1 -1
- package/dist/tools/common-schemas.d.ts +3 -0
- package/dist/tools/common-schemas.d.ts.map +1 -1
- package/dist/tools/common-schemas.js +7 -0
- package/dist/tools/common-schemas.js.map +1 -1
- package/dist/tools/csv-export.d.ts +122 -119
- package/dist/tools/csv-export.d.ts.map +1 -1
- package/dist/tools/csv-export.js +17 -2
- package/dist/tools/csv-export.js.map +1 -1
- package/dist/tools/enum-providers.d.ts.map +1 -1
- package/dist/tools/enum-providers.js +21 -7
- package/dist/tools/enum-providers.js.map +1 -1
- package/dist/tools/get-operations.d.ts +1 -1
- package/dist/tools/get-operations.d.ts.map +1 -1
- package/dist/tools/get-operations.js +3 -1
- package/dist/tools/get-operations.js.map +1 -1
- package/dist/tools/job-scripts.d.ts.map +1 -1
- package/dist/tools/job-scripts.js +19 -11
- package/dist/tools/job-scripts.js.map +1 -1
- package/dist/tools/layout-richstring-widgets.d.ts +2 -2
- package/dist/tools/layout-richstring-widgets.d.ts.map +1 -1
- package/dist/tools/layout-richstring-widgets.js +16 -6
- package/dist/tools/layout-richstring-widgets.js.map +1 -1
- package/dist/tools/layout.d.ts +21 -6
- package/dist/tools/layout.d.ts.map +1 -1
- package/dist/tools/layout.js +19 -9
- package/dist/tools/layout.js.map +1 -1
- package/dist/tools/linting.d.ts +1 -1
- package/dist/tools/linting.js +1 -1
- package/dist/tools/linting.js.map +1 -1
- package/dist/tools/page-actions.d.ts.map +1 -1
- package/dist/tools/page-actions.js +19 -11
- package/dist/tools/page-actions.js.map +1 -1
- package/dist/tools/pages.d.ts +3 -3
- package/dist/tools/pages.d.ts.map +1 -1
- package/dist/tools/pages.js +54 -15
- package/dist/tools/pages.js.map +1 -1
- package/dist/tools/profile-management.d.ts +2 -0
- package/dist/tools/profile-management.d.ts.map +1 -1
- package/dist/tools/profile-management.js +6 -5
- package/dist/tools/profile-management.js.map +1 -1
- package/dist/tools/richstring-widgets.js +3 -3
- package/dist/tools/richstring-widgets.js.map +1 -1
- package/dist/tools/search.d.ts +142 -122
- package/dist/tools/search.d.ts.map +1 -1
- package/dist/tools/search.js +71 -23
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/type-management.d.ts +13 -14
- package/dist/tools/type-management.d.ts.map +1 -1
- package/dist/tools/type-management.js +134 -49
- package/dist/tools/type-management.js.map +1 -1
- package/dist/tools/validators.d.ts +1 -1
- package/dist/tools/validators.d.ts.map +1 -1
- package/dist/tools/validators.js +24 -8
- package/dist/tools/validators.js.map +1 -1
- package/dist/tools/widget-simulation-legacy.d.ts.map +1 -1
- package/dist/tools/widget-simulation-legacy.js.map +1 -1
- package/dist/tools/widget-simulation.d.ts.map +1 -1
- package/dist/tools/widget-simulation.js +2 -3
- package/dist/tools/widget-simulation.js.map +1 -1
- package/dist/tools/wizards.d.ts.map +1 -1
- package/dist/tools/wizards.js +3 -2
- package/dist/tools/wizards.js.map +1 -1
- package/dist/tools/workflow-scripts.d.ts +2 -2
- package/dist/tools/workflow-scripts.d.ts.map +1 -1
- package/dist/tools/workflow-scripts.js +21 -11
- package/dist/tools/workflow-scripts.js.map +1 -1
- package/dist/tools/workflow.d.ts +5 -2
- package/dist/tools/workflow.d.ts.map +1 -1
- package/dist/tools/workflow.js +26 -3
- package/dist/tools/workflow.js.map +1 -1
- package/dist/tools/workspace-core.d.ts +2 -1
- package/dist/tools/workspace-core.d.ts.map +1 -1
- package/dist/tools/workspace-core.js +22 -7
- package/dist/tools/workspace-core.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +17 -0
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -12,25 +12,46 @@ A hosted MCP server is available at [mcp.cplace.com](https://mcp.cplace.com/). T
|
|
|
12
12
|
|
|
13
13
|
#### Claude Code
|
|
14
14
|
```bash
|
|
15
|
-
claude mcp add --transport http cplace https://mcp.cplace.com --header "cplace-url: https://${CPLACE_PROJECT_API_TOKEN}@base.cplace.io"
|
|
15
|
+
claude mcp add --transport http cplace-base https://mcp.cplace.com --header "cplace-url: https://${CPLACE_PROJECT_API_TOKEN}@base.cplace.io"
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
The name you register (`cplace-base` here) becomes part of every tool name, as in `mcp__cplace-base__cplace_search_pages`. Skills in the cplace marketplace expect `cplace-base` for base.cplace.io. For any other instance, pick one name per instance, such as `cplace-dev` for a project's dev instance.
|
|
19
|
+
|
|
18
20
|
You can optionally choose which tool profiles to load for the connection with a `cplace-profiles` header (HTTP/remote only). It uses the same value grammar as `--profiles=` and is read only when the connection is established (reconnect to change it):
|
|
19
21
|
|
|
20
22
|
```bash
|
|
21
23
|
# Load core + types-write + low-code
|
|
22
|
-
claude mcp add --transport http cplace https://mcp.cplace.com \
|
|
24
|
+
claude mcp add --transport http cplace-base https://mcp.cplace.com \
|
|
23
25
|
--header "cplace-url: https://${CPLACE_PROJECT_API_TOKEN}@base.cplace.io" \
|
|
24
26
|
--header "cplace-profiles: types-write+low-code"
|
|
25
27
|
|
|
26
28
|
# Load all available profiles
|
|
27
|
-
claude mcp add --transport http cplace https://mcp.cplace.com \
|
|
29
|
+
claude mcp add --transport http cplace-base https://mcp.cplace.com \
|
|
28
30
|
--header "cplace-url: https://${CPLACE_PROJECT_API_TOKEN}@base.cplace.io" \
|
|
29
31
|
--header "cplace-profiles: all"
|
|
30
32
|
```
|
|
31
33
|
|
|
32
34
|
When set, the `cplace-profiles` header takes precedence over any saved preference for that token+tenant. If omitted (or empty), the server falls back to the stored preference, then `--profiles=`, then the `core` default. See [Profile Resolution Priority](#profile-resolution-priority).
|
|
33
35
|
|
|
36
|
+
#### Strict input schemas (OpenAI strict-mode gateways)
|
|
37
|
+
|
|
38
|
+
Some gateways, such as those that call OpenAI models in strict mode, refuse tool schemas with optional parameters or open objects. For them, send the `cplace-schemas: strict` header (or start a local server with `--schemas=strict`). Like `cplace-profiles`, it is read only when the connection is established.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
claude mcp add --transport http cplace-base https://mcp.cplace.com \
|
|
42
|
+
--header "cplace-url: https://${CPLACE_PROJECT_API_TOKEN}@base.cplace.io" \
|
|
43
|
+
--header "cplace-schemas: strict"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
In such a connection every parameter is listed as required:
|
|
47
|
+
|
|
48
|
+
- An unused parameter is sent as `null`.
|
|
49
|
+
- A map, such as localized names, is a list of `{"key": …, "value": …}` entries.
|
|
50
|
+
- A value of any shape, such as page attributes, is a string holding JSON.
|
|
51
|
+
- Limits and defaults are stated in the parameter description.
|
|
52
|
+
|
|
53
|
+
The tools behave the same as in a standard connection. Without the header, nothing changes.
|
|
54
|
+
|
|
34
55
|
#### Claude Desktop
|
|
35
56
|
|
|
36
57
|
Claude Desktop cannot connect to the remote server directly: its connector UI supports only authless or OAuth servers, and the cplace MCP server authenticates via custom headers (`cplace-url`, `cplace-api-token`). Use the [local installation](#local-installation-alternative) below, or bridge the remote server with `mcp-remote`:
|
|
@@ -38,7 +59,7 @@ Claude Desktop cannot connect to the remote server directly: its connector UI su
|
|
|
38
59
|
```json
|
|
39
60
|
{
|
|
40
61
|
"mcpServers": {
|
|
41
|
-
"cplace": {
|
|
62
|
+
"cplace-your-instance": {
|
|
42
63
|
"command": "npx",
|
|
43
64
|
"args": [
|
|
44
65
|
"-y", "mcp-remote", "https://mcp.cplace.com/mcp",
|
|
@@ -62,7 +83,7 @@ By default, only the core tools are loaded. Add this entry to your Claude Deskto
|
|
|
62
83
|
```json
|
|
63
84
|
{
|
|
64
85
|
"mcpServers": {
|
|
65
|
-
"cplace": {
|
|
86
|
+
"cplace-your-instance": {
|
|
66
87
|
"command": "npx",
|
|
67
88
|
"args": ["-y", "@cplace/mcp-server@latest"],
|
|
68
89
|
"env": {
|
|
@@ -78,7 +99,7 @@ By default, only the core tools are loaded. Add this entry to your Claude Deskto
|
|
|
78
99
|
```json
|
|
79
100
|
{
|
|
80
101
|
"mcpServers": {
|
|
81
|
-
"cplace": {
|
|
102
|
+
"cplace-your-instance": {
|
|
82
103
|
"command": "npx",
|
|
83
104
|
"args": ["-y", "@cplace/mcp-server@latest"],
|
|
84
105
|
"env": {
|
|
@@ -95,7 +116,7 @@ Claude Code has built-in Tool Search that defers tool loading until needed, so t
|
|
|
95
116
|
|
|
96
117
|
**Option 1: Separate credentials**
|
|
97
118
|
```bash
|
|
98
|
-
claude mcp add cplace \
|
|
119
|
+
claude mcp add cplace-your-instance \
|
|
99
120
|
--env CPLACE_URL=https://your-cplace-instance.com/your-tenant \
|
|
100
121
|
--env API_TOKEN=your-api-token \
|
|
101
122
|
-- npx -y @cplace/mcp-server@latest --profiles=all
|
|
@@ -103,7 +124,7 @@ claude mcp add cplace \
|
|
|
103
124
|
|
|
104
125
|
**Option 2: URL-embedded credentials**
|
|
105
126
|
```bash
|
|
106
|
-
claude mcp add cplace \
|
|
127
|
+
claude mcp add cplace-your-instance \
|
|
107
128
|
--env CPLACE_URL=https://your-api-token@your-cplace-instance.com/your-tenant \
|
|
108
129
|
-- npx -y @cplace/mcp-server@latest --profiles=all
|
|
109
130
|
```
|
|
@@ -174,11 +195,7 @@ The following configuration properties must be set for API Token authentication
|
|
|
174
195
|
|
|
175
196
|
## Usage
|
|
176
197
|
|
|
177
|
-
1.
|
|
178
|
-
* Navigate to your user profile in cplace
|
|
179
|
-
* Click on "Action" -> "View my API Tokens" 
|
|
180
|
-
* Create a new API Token
|
|
181
|
-
* Copy the token value 
|
|
198
|
+
1. In your cplace user profile, create an API token and copy the token value. The value is shown only once. For instructions, see ["API Tokens"](https://kb.cplace.com/user-manual/using-cplace/changing-user-settings/api-tokens) in the cplace user manual. For how the MCP server uses the token, see ["Configuration"](https://kb.cplace.com/cplace-mcp-server/configuration).
|
|
182
199
|
2. Configure your credentials (see Installation section above)
|
|
183
200
|
3. If Claude Desktop is running, close it
|
|
184
201
|
4. Add the MCP server configuration to Claude Desktop
|
|
@@ -326,7 +343,7 @@ Essential operations including workspace navigation, page CRUD operations, searc
|
|
|
326
343
|
**Workspace Management:**
|
|
327
344
|
- `cplace_list_workspaces` - Get all workspaces with essential properties
|
|
328
345
|
- `cplace_get_workspace_details` - Get comprehensive details about a specific workspace including all metadata, permissions, type definitions, styling, and configuration
|
|
329
|
-
- `cplace_list_types` - List
|
|
346
|
+
- `cplace_list_types` - List the types available in a workspace, optionally only those whose name contains a text (`nameContains`)
|
|
330
347
|
- `cplace_get_type_datamodel` - Get the datamodel of a type including its attributes, constraints, and permissions
|
|
331
348
|
|
|
332
349
|
**Page Operations:**
|
|
@@ -2,7 +2,7 @@ import type { CplaceApiClient, VersionApiResponse } from './api.js';
|
|
|
2
2
|
export declare const FLOOR_LABEL = "1.12";
|
|
3
3
|
export declare const FROZEN_LABEL = "1.17";
|
|
4
4
|
export declare const DETECTION_TIMEOUT_MS = 5000;
|
|
5
|
-
export type Capability = 'decoded-widget-v1' | 'workflow.guards-enforced' | 'script.nested-results' | 'constraint.clear' | 'workflow.state-before-scripts' | 'layout.keep-inherited-widgets' | 'app-configuration.read' | 'change-listener.event-types' | 'widget-sim.script-contexts';
|
|
5
|
+
export type Capability = 'decoded-widget-v1' | 'workflow.guards-enforced' | 'script.nested-results' | 'constraint.clear' | 'workflow.state-before-scripts' | 'layout.keep-inherited-widgets' | 'app-configuration.read' | 'change-listener.event-types' | 'widget-sim.script-contexts' | 'workflow.update-keeps-scripts' | 'search.begins-with-prefix' | 'search.failure-reported' | 'layout.validation-warnings' | 'type-definition.update-permissions' | 'layout.remove-unknown-id-fails' | 'layout.script-keeps-widget-ids' | 'search.dropped-filters-rejected' | 'decoded-widget.property-values-validated' | 'reference.update-to-any' | 'constraint.show-in-menu-if-hierarchy' | 'page.package-inclusion' | 'type-definition.default-package-inclusion' | 'constraint.script' | 'constraint.search' | 'workflow.default-state-applied';
|
|
6
6
|
interface TableEntry {
|
|
7
7
|
capability: Capability;
|
|
8
8
|
since: string;
|
|
@@ -23,6 +23,14 @@ export declare function belowFloorMessage(snapshot: BackendSnapshot): string;
|
|
|
23
23
|
export declare class BelowFloorError extends Error {
|
|
24
24
|
constructor(snapshot: BackendSnapshot);
|
|
25
25
|
}
|
|
26
|
+
export declare function floorRefusalBody(error: BelowFloorError): {
|
|
27
|
+
jsonrpc: "2.0";
|
|
28
|
+
error: {
|
|
29
|
+
code: number;
|
|
30
|
+
message: string;
|
|
31
|
+
};
|
|
32
|
+
id: null;
|
|
33
|
+
};
|
|
26
34
|
export declare class BackendCapabilities {
|
|
27
35
|
private readonly client;
|
|
28
36
|
private readonly timeoutMs;
|
|
@@ -36,6 +44,7 @@ export declare class BackendCapabilities {
|
|
|
36
44
|
static unknown(reason: string): BackendCapabilities;
|
|
37
45
|
get snapshot(): BackendSnapshot | undefined;
|
|
38
46
|
get unknownReason(): string | undefined;
|
|
47
|
+
assertAboveFloor(): void;
|
|
39
48
|
gateHas(capability: Capability): boolean;
|
|
40
49
|
guardHas(capability: Capability): Promise<boolean>;
|
|
41
50
|
refreshIfUnknown(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend-capabilities.d.ts","sourceRoot":"","sources":["../src/backend-capabilities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"backend-capabilities.d.ts","sourceRoot":"","sources":["../src/backend-capabilities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AA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AAGD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe;;;;;;;EAMtD;AAwBD,qBAAa,mBAAmB;IAM5B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAN5B,OAAO,CAAC,KAAK,CAAC,CAAkB;IAChC,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAgB;IAEhC,OAAO;WASM,MAAM,CACjB,MAAM,EAAE,eAAe,EACvB,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAC5B,OAAO,CAAC,mBAAmB,CAAC;IAM/B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,mBAAmB;IAKnD,IAAI,QAAQ,IAAI,eAAe,GAAG,SAAS,CAE1C;IAED,IAAI,aAAa,IAAI,MAAM,GAAG,SAAS,CAEtC;IAGD,gBAAgB,IAAI,IAAI;IAOxB,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO;IAKlC,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAMlD,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAYvC,KAAK,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IASzC,OAAO,CAAC,KAAK;IASb,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAalC"}
|
|
@@ -13,6 +13,7 @@ export const CAPABILITY_TABLE = [
|
|
|
13
13
|
{ capability: 'app-configuration.read', since: '1.15' },
|
|
14
14
|
{ capability: 'change-listener.event-types', since: '1.15', platform: '26.2' },
|
|
15
15
|
{ capability: 'widget-sim.script-contexts', since: '1.16' },
|
|
16
|
+
{ capability: 'decoded-widget.property-values-validated', since: '1.16' },
|
|
16
17
|
];
|
|
17
18
|
const FLOOR_CAPABILITIES = CAPABILITY_TABLE.filter((entry) => !entry.platform && labelGte(FLOOR_LABEL, entry.since)).map((entry) => entry.capability);
|
|
18
19
|
export function labelGte(a, b) {
|
|
@@ -64,6 +65,13 @@ export class BelowFloorError extends Error {
|
|
|
64
65
|
this.name = 'BelowFloorError';
|
|
65
66
|
}
|
|
66
67
|
}
|
|
68
|
+
export function floorRefusalBody(error) {
|
|
69
|
+
return {
|
|
70
|
+
jsonrpc: '2.0',
|
|
71
|
+
error: { code: -32000, message: `Bad Request: ${error.message}` },
|
|
72
|
+
id: null,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
67
75
|
async function runDetection(client, timeoutMs) {
|
|
68
76
|
const signal = AbortSignal.timeout(timeoutMs);
|
|
69
77
|
try {
|
|
@@ -101,6 +109,11 @@ export class BackendCapabilities {
|
|
|
101
109
|
get unknownReason() {
|
|
102
110
|
return this.known ? undefined : this.reason;
|
|
103
111
|
}
|
|
112
|
+
assertAboveFloor() {
|
|
113
|
+
if (this.known?.belowFloor) {
|
|
114
|
+
throw new BelowFloorError(this.known);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
104
117
|
gateHas(capability) {
|
|
105
118
|
return this.known ? this.known.capabilities.has(capability) : true;
|
|
106
119
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend-capabilities.js","sourceRoot":"","sources":["../src/backend-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"backend-capabilities.js","sourceRoot":"","sources":["../src/backend-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAYtD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC;AAElC,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC;AAEnC,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI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KAAK,CAAC,KAAsB;QAClC,IAAI,UAAU,IAAI,KAAK,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC7B,CAAC;IACH,CAAC;IAGD,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QAC5D,CAAC;QACD,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;YACzB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK;YACvB,eAAe,EAAE,IAAI,CAAC,KAAK,CAAC,eAAe;YAC3C,YAAY,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE;YACjD,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU;YACjC,KAAK,EAAE,WAAW;SACnB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type ZodRawShape, type ZodTypeAny } from 'zod';
|
|
3
3
|
import type { BackendCapabilities, Capability } from './backend-capabilities.js';
|
|
4
|
+
import { type InputSchemaMode } from './strict-schemas.js';
|
|
4
5
|
export declare function requires<T extends ZodTypeAny>(schema: T, capability: Capability): T;
|
|
5
6
|
export declare function ifCap(capability: Capability, text: string): string;
|
|
6
7
|
export declare function ifNoCap(capability: Capability, text: string): string;
|
|
@@ -18,12 +19,16 @@ export interface GatingDeclarations {
|
|
|
18
19
|
unless?: Capability;
|
|
19
20
|
guards?: readonly Guard[];
|
|
20
21
|
}
|
|
22
|
+
export declare function backendHas(backend: BackendCapabilities): (capability: string) => boolean;
|
|
23
|
+
export declare function isOffered(config: GatingDeclarations, has: (capability: string) => boolean): boolean;
|
|
21
24
|
export interface GatingReport {
|
|
22
25
|
gatedTools: string[];
|
|
23
26
|
gatedParameters: string[];
|
|
24
27
|
}
|
|
25
28
|
export declare function backendName(backend: BackendCapabilities): string;
|
|
26
|
-
export declare function gateServer(server: McpServer, backend: BackendCapabilities
|
|
29
|
+
export declare function gateServer(server: McpServer, backend: BackendCapabilities, options?: {
|
|
30
|
+
inputSchemas?: InputSchemaMode;
|
|
31
|
+
}): {
|
|
27
32
|
server: McpServer;
|
|
28
33
|
report: GatingReport;
|
|
29
34
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-gating.d.ts","sourceRoot":"","sources":["../src/capability-gating.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"capability-gating.d.ts","sourceRoot":"","sources":["../src/capability-gating.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAK,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAC;AA6B7B,wBAAgB,QAAQ,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,UAAU,GAAG,CAAC,CAGnF;AAGD,wBAAgB,KAAK,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAElE;AAGD,wBAAgB,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpE;AAKD,wBAAgB,WAAW,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import { z } from 'zod';
|
|
2
|
+
import { fromStrictArguments, StrictArgumentError, toStrictSchema, } from './strict-schemas.js';
|
|
1
3
|
const requiredBySchema = new WeakMap();
|
|
2
4
|
export function requires(schema, capability) {
|
|
3
5
|
requiredBySchema.set(schema, capability);
|
|
@@ -38,9 +40,12 @@ function resolveNode(node, has, path, dropped) {
|
|
|
38
40
|
}
|
|
39
41
|
else if (typeName === 'ZodObject') {
|
|
40
42
|
const shape = node.shape;
|
|
43
|
+
const before = dropped.length;
|
|
41
44
|
const next = resolveShapeAt(shape, has, `${path}.`, dropped);
|
|
42
45
|
if (next !== shape)
|
|
43
46
|
changes.shape = () => next;
|
|
47
|
+
if (dropped.length > before)
|
|
48
|
+
changes.unknownKeys = 'strict';
|
|
44
49
|
}
|
|
45
50
|
if (resolved !== description)
|
|
46
51
|
changes.description = resolved;
|
|
@@ -67,6 +72,15 @@ export function resolveShape(shape, has) {
|
|
|
67
72
|
const dropped = [];
|
|
68
73
|
return { shape: resolveShapeAt(shape, has, '', dropped), dropped };
|
|
69
74
|
}
|
|
75
|
+
export function backendHas(backend) {
|
|
76
|
+
return (capability) => backend.gateHas(capability);
|
|
77
|
+
}
|
|
78
|
+
function lacksRequirement(config, has) {
|
|
79
|
+
return !!config.requires && !has(config.requires);
|
|
80
|
+
}
|
|
81
|
+
export function isOffered(config, has) {
|
|
82
|
+
return !(config.unless && has(config.unless)) && !lacksRequirement(config, has);
|
|
83
|
+
}
|
|
70
84
|
export function backendName(backend) {
|
|
71
85
|
const label = backend.snapshot?.label;
|
|
72
86
|
return label ? `Backend ${label}` : 'This backend';
|
|
@@ -90,30 +104,57 @@ function guardHandler(guards, backend, handler) {
|
|
|
90
104
|
return handler(...callArgs);
|
|
91
105
|
};
|
|
92
106
|
}
|
|
93
|
-
|
|
107
|
+
function invalidArguments(name, message) {
|
|
108
|
+
return errorResult(`Input validation error: Invalid arguments for tool ${name}: ${message}`);
|
|
109
|
+
}
|
|
110
|
+
function strictHandler(name, original, handler) {
|
|
111
|
+
return async (args, ...rest) => {
|
|
112
|
+
let mapped;
|
|
113
|
+
try {
|
|
114
|
+
mapped = fromStrictArguments(args ?? {}, original);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (error instanceof StrictArgumentError)
|
|
118
|
+
return invalidArguments(name, error.message);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
const parsed = await original.safeParseAsync(mapped);
|
|
122
|
+
if (!parsed.success)
|
|
123
|
+
return invalidArguments(name, parsed.error.message);
|
|
124
|
+
return handler(parsed.data, ...rest);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export function gateServer(server, backend, options = {}) {
|
|
94
128
|
const report = { gatedTools: [], gatedParameters: [] };
|
|
95
129
|
const registered = new Set();
|
|
96
|
-
const has = (
|
|
130
|
+
const has = backendHas(backend);
|
|
97
131
|
const registerTool = (name, config, handler) => {
|
|
98
132
|
const { requires: required, unless, guards, ...rest } = config;
|
|
99
|
-
if (unless
|
|
100
|
-
|
|
101
|
-
if (required && !has(required)) {
|
|
102
|
-
if (!registered.has(name))
|
|
133
|
+
if (!isOffered({ requires: required, unless }, has)) {
|
|
134
|
+
if (lacksRequirement({ requires: required }, has) && !registered.has(name)) {
|
|
103
135
|
report.gatedTools.push(name);
|
|
136
|
+
}
|
|
104
137
|
return undefined;
|
|
105
138
|
}
|
|
106
139
|
const next = { ...rest };
|
|
107
140
|
if (typeof rest.description === 'string')
|
|
108
141
|
next.description = resolveText(rest.description, has);
|
|
142
|
+
let run = guards?.length ? guardHandler(guards, backend, handler) : handler;
|
|
109
143
|
if (rest.inputSchema) {
|
|
110
144
|
const { shape, dropped } = resolveShape(rest.inputSchema, has);
|
|
111
|
-
|
|
145
|
+
const original = z.object(shape).strict();
|
|
146
|
+
if (options.inputSchemas === 'strict') {
|
|
147
|
+
next.inputSchema = toStrictSchema(shape, name);
|
|
148
|
+
run = strictHandler(name, original, run);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
next.inputSchema = original;
|
|
152
|
+
}
|
|
112
153
|
report.gatedParameters.push(...dropped.map((key) => `${name}.${key}`));
|
|
113
154
|
}
|
|
114
155
|
registered.add(name);
|
|
115
156
|
report.gatedTools = report.gatedTools.filter((tool) => tool !== name);
|
|
116
|
-
return server.registerTool(name, next,
|
|
157
|
+
return server.registerTool(name, next, run);
|
|
117
158
|
};
|
|
118
159
|
const gated = new Proxy(server, {
|
|
119
160
|
get(target, property) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-gating.js","sourceRoot":"","sources":["../src/capability-gating.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"capability-gating.js","sourceRoot":"","sources":["../src/capability-gating.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAqC,MAAM,KAAK,CAAC;AAE3D,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,GAEf,MAAM,qBAAqB,CAAC;AA0B7B,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAA0B,CAAC;AAG/D,MAAM,UAAU,QAAQ,CAAuB,MAAS,EAAE,UAAsB;IAC9E,gBAAgB,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC;AAChB,CAAC;AAGD,MAAM,UAAU,KAAK,CAAC,UAAsB,EAAE,IAAY;IACxD,OAAO,KAAK,UAAU,IAAI,IAAI,KAAK,CAAC;AACtC,CAAC;AAGD,MAAM,UAAU,OAAO,CAAC,UAAsB,EAAE,IAAY;IAC1D,OAAO,KAAK,UAAU,IAAI,IAAI,KAAK,CAAC;AACtC,CAAC;AAED,MAAM,MAAM,GAAG,gCAAgC,CAAC;AAGhD,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,GAAoC;IAC5E,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,IAAY,EAAE,UAAkB,EAAE,IAAY,EAAE,EAAE,CACr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AK,CAAC,MAAM,EAAE;QAC9B,GAAG,CAAC,MAAM,EAAE,QAAQ;YAClB,IAAI,QAAQ,KAAK,cAAc;gBAAE,OAAO,YAAY,CAAC;YACrD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;YACpD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAClE,CAAC;KACF,CAAC,CAAC;IACH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AACnC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,14 +15,15 @@ import { registerProfileManagementTools } from './tools/profile-management.js';
|
|
|
15
15
|
import { getPreference } from './preference-file.js';
|
|
16
16
|
import { registerWidgetTools } from './tools/widgets.js';
|
|
17
17
|
import { registerAppCatalogTools } from './tools/apps-catalog.js';
|
|
18
|
-
import { primeCustomConstraintTypeCache } from './tools/type-management.js';
|
|
19
18
|
import { debugLogWithTag } from './logger.js';
|
|
20
19
|
import { parseUrlCredentials, hasEmbeddedCredentials } from './url-parsing.js';
|
|
21
20
|
import { loadExternalPlugins } from './plugin-loader.js';
|
|
22
21
|
import { cleanupIdleSessions } from './session-cleanup.js';
|
|
22
|
+
import { UNKNOWN_SESSION, MISSING_SESSION_ID } from './session-responses.js';
|
|
23
23
|
import { SERVER_IDENTITY, SERVER_VERSION } from './server-identity.js';
|
|
24
|
-
import { BackendCapabilities, BelowFloorError } from './backend-capabilities.js';
|
|
24
|
+
import { BackendCapabilities, BelowFloorError, floorRefusalBody } from './backend-capabilities.js';
|
|
25
25
|
import { gateServer } from './capability-gating.js';
|
|
26
|
+
import { parseInputSchemaMode } from './strict-schemas.js';
|
|
26
27
|
dotenv.config();
|
|
27
28
|
function parsePositiveIntEnv(name, defaultMs) {
|
|
28
29
|
const raw = process.env[name];
|
|
@@ -75,9 +76,6 @@ const config = (() => {
|
|
|
75
76
|
};
|
|
76
77
|
})();
|
|
77
78
|
const client = new CplaceApiClient(config);
|
|
78
|
-
if (config.url && config.apiToken) {
|
|
79
|
-
await primeCustomConstraintTypeCache(client);
|
|
80
|
-
}
|
|
81
79
|
const registry = new PluginRegistry();
|
|
82
80
|
await loadExternalPlugins(process.argv, registry);
|
|
83
81
|
const collisionWarnings = registry.validateToolNameCollisions();
|
|
@@ -96,17 +94,24 @@ function checkBackend(backend) {
|
|
|
96
94
|
debugLogWithTag('MCP', snapshot
|
|
97
95
|
? `Backend label ${snapshot.label} (${snapshot.source}): ${snapshot.capabilities.size} capabilities`
|
|
98
96
|
: `Backend capabilities unknown: ${backend.unknownReason}`);
|
|
99
|
-
|
|
100
|
-
throw new BelowFloorError(snapshot);
|
|
101
|
-
}
|
|
97
|
+
backend.assertAboveFloor();
|
|
102
98
|
}
|
|
99
|
+
const schemasArgument = process.argv.find((a) => a.startsWith('--schemas='));
|
|
100
|
+
const parsedStdioSchemas = parseInputSchemaMode(schemasArgument?.slice('--schemas='.length));
|
|
101
|
+
if (!parsedStdioSchemas) {
|
|
102
|
+
console.error('[cplace-mcp] --schemas must be "strict" or "standard"');
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
const stdioInputSchemas = parsedStdioSchemas;
|
|
103
106
|
async function createStdioServer() {
|
|
104
107
|
const backend = config.url && config.apiToken
|
|
105
108
|
? await BackendCapabilities.detect(client)
|
|
106
109
|
: BackendCapabilities.unknown('no CPLACE_URL / API_TOKEN configured');
|
|
107
110
|
checkBackend(backend);
|
|
108
111
|
const stdioServer = new McpServer(SERVER_IDENTITY);
|
|
109
|
-
const { server: gated, report } = gateServer(stdioServer, backend
|
|
112
|
+
const { server: gated, report } = gateServer(stdioServer, backend, {
|
|
113
|
+
inputSchemas: stdioInputSchemas,
|
|
114
|
+
});
|
|
110
115
|
registry.registerTools(gated, client, activeGroups);
|
|
111
116
|
const mergedSpecs = registry.getAggregatedWidgetSpecifications(activeGroups);
|
|
112
117
|
registerWidgetTools(gated, client, mergedSpecs);
|
|
@@ -129,6 +134,7 @@ async function createStdioServer() {
|
|
|
129
134
|
resolvedProfiles: [...activeGroups],
|
|
130
135
|
source: stdioSource,
|
|
131
136
|
transport: 'stdio',
|
|
137
|
+
inputSchemas: stdioInputSchemas,
|
|
132
138
|
backend,
|
|
133
139
|
}), registry);
|
|
134
140
|
return stdioServer;
|
|
@@ -199,12 +205,12 @@ function validateCredentials(cplaceUrl, apiToken) {
|
|
|
199
205
|
}
|
|
200
206
|
return { valid: true };
|
|
201
207
|
}
|
|
202
|
-
async function createSessionServer(cplaceUrl, apiToken, profilesHeader) {
|
|
208
|
+
async function createSessionServer(cplaceUrl, apiToken, profilesHeader, inputSchemas) {
|
|
203
209
|
const sessionClient = new CplaceApiClient({ url: ensureTrailingSlash(cplaceUrl), apiToken });
|
|
204
210
|
const backend = await BackendCapabilities.detect(sessionClient);
|
|
205
211
|
checkBackend(backend);
|
|
206
212
|
const sessionServer = new McpServer(SERVER_IDENTITY);
|
|
207
|
-
const { server: gated, report } = gateServer(sessionServer, backend);
|
|
213
|
+
const { server: gated, report } = gateServer(sessionServer, backend, { inputSchemas });
|
|
208
214
|
const sessionGroups = parseProfiles(process.argv, apiToken, cplaceUrl, registry.getAvailableProfileNames(), profilesHeader);
|
|
209
215
|
registry.registerTools(gated, sessionClient, sessionGroups);
|
|
210
216
|
const mergedSpecs = registry.getAggregatedWidgetSpecifications(sessionGroups);
|
|
@@ -236,6 +242,7 @@ async function createSessionServer(cplaceUrl, apiToken, profilesHeader) {
|
|
|
236
242
|
resolvedProfiles: [...sessionGroups],
|
|
237
243
|
source,
|
|
238
244
|
transport: 'http',
|
|
245
|
+
inputSchemas,
|
|
239
246
|
backend,
|
|
240
247
|
}), registry);
|
|
241
248
|
return { server: sessionServer, client: sessionClient };
|
|
@@ -244,8 +251,8 @@ function startHttpServer() {
|
|
|
244
251
|
const app = express();
|
|
245
252
|
const port = process.env.PORT || 3000;
|
|
246
253
|
const sessions = {};
|
|
247
|
-
const createSession = async (cplaceUrl, apiToken, profilesHeader) => {
|
|
248
|
-
const { server: sessionServer, client: sessionClient } = await createSessionServer(cplaceUrl, apiToken, profilesHeader);
|
|
254
|
+
const createSession = async (cplaceUrl, apiToken, profilesHeader, inputSchemas) => {
|
|
255
|
+
const { server: sessionServer, client: sessionClient } = await createSessionServer(cplaceUrl, apiToken, profilesHeader, inputSchemas);
|
|
249
256
|
const transport = new StreamableHTTPServerTransport({
|
|
250
257
|
sessionIdGenerator: () => randomUUID(),
|
|
251
258
|
onsessioninitialized: (newSessionId) => {
|
|
@@ -289,7 +296,7 @@ function startHttpServer() {
|
|
|
289
296
|
reapedWithStream: 0,
|
|
290
297
|
reapedWithoutStream: 0,
|
|
291
298
|
maxLifetimeCloses: 0,
|
|
292
|
-
|
|
299
|
+
unknownSessionResponses: 0,
|
|
293
300
|
};
|
|
294
301
|
const cleanupTimer = setInterval(() => {
|
|
295
302
|
const { withStream, withoutStream } = cleanupIdleSessions(sessions, SESSION_IDLE_TIMEOUT_MS, STREAM_IDLE_TIMEOUT_MS);
|
|
@@ -297,8 +304,6 @@ function startHttpServer() {
|
|
|
297
304
|
counters.reapedWithoutStream += withoutStream;
|
|
298
305
|
}, CLEANUP_INTERVAL_MS);
|
|
299
306
|
debugLogWithTag('MCP', `🕐 Session cleanup timer started (interval: ${CLEANUP_INTERVAL_MS / 60000} min, idle timeout: ${SESSION_IDLE_TIMEOUT_MS / 60000} min, stream idle grace: ${STREAM_IDLE_TIMEOUT_MS / 60000} min, SSE keepalive: ${SSE_KEEPALIVE_MS / 1000}s, max stream lifetime: ${SSE_MAX_STREAM_LIFETIME_MS / 60000} min)`);
|
|
300
|
-
process.on('SIGTERM', () => clearInterval(cleanupTimer));
|
|
301
|
-
process.on('SIGINT', () => clearInterval(cleanupTimer));
|
|
302
307
|
app.use(cors({
|
|
303
308
|
origin: '*',
|
|
304
309
|
credentials: true,
|
|
@@ -308,6 +313,7 @@ function startHttpServer() {
|
|
|
308
313
|
'cplace-url',
|
|
309
314
|
'cplace-api-token',
|
|
310
315
|
'cplace-profiles',
|
|
316
|
+
'cplace-schemas',
|
|
311
317
|
],
|
|
312
318
|
exposedHeaders: ['mcp-session-id'],
|
|
313
319
|
}));
|
|
@@ -339,6 +345,7 @@ function startHttpServer() {
|
|
|
339
345
|
version: SERVER_VERSION,
|
|
340
346
|
buildTime: process.env.BUILD_TIME || 'unknown',
|
|
341
347
|
timestamp: new Date().toISOString(),
|
|
348
|
+
uptimeSeconds: Math.round(process.uptime()),
|
|
342
349
|
activeSessions: sessionValues.length,
|
|
343
350
|
activeStreams,
|
|
344
351
|
oldestSessionAgeMinutes,
|
|
@@ -355,7 +362,7 @@ function startHttpServer() {
|
|
|
355
362
|
reapedWithStream: counters.reapedWithStream,
|
|
356
363
|
reapedWithoutStream: counters.reapedWithoutStream,
|
|
357
364
|
maxLifetimeCloses: counters.maxLifetimeCloses,
|
|
358
|
-
|
|
365
|
+
unknownSessionResponses: counters.unknownSessionResponses,
|
|
359
366
|
},
|
|
360
367
|
});
|
|
361
368
|
});
|
|
@@ -382,16 +389,9 @@ function startHttpServer() {
|
|
|
382
389
|
sessionInfo.lastActivityAt = new Date();
|
|
383
390
|
}
|
|
384
391
|
else if (sessionId && !sessions[sessionId]) {
|
|
385
|
-
counters.
|
|
386
|
-
debugLogWithTag('MCP', `❌ Session not found
|
|
387
|
-
res.status(
|
|
388
|
-
jsonrpc: '2.0',
|
|
389
|
-
error: {
|
|
390
|
-
code: -32000,
|
|
391
|
-
message: 'Session expired or not found. Please reconnect by sending a new initialize request.',
|
|
392
|
-
},
|
|
393
|
-
id: null,
|
|
394
|
-
});
|
|
392
|
+
counters.unknownSessionResponses++;
|
|
393
|
+
debugLogWithTag('MCP', `❌ Session not found: ${sessionId}`);
|
|
394
|
+
res.status(UNKNOWN_SESSION.status).json(UNKNOWN_SESSION.body);
|
|
395
395
|
return;
|
|
396
396
|
}
|
|
397
397
|
else if (!sessionId && isInitializeRequest(req.body)) {
|
|
@@ -409,24 +409,30 @@ function startHttpServer() {
|
|
|
409
409
|
return;
|
|
410
410
|
}
|
|
411
411
|
const profilesHeader = req.headers['cplace-profiles'];
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
catch (error) {
|
|
417
|
-
if (!(error instanceof BelowFloorError))
|
|
418
|
-
throw error;
|
|
419
|
-
debugLogWithTag('MCP', `❌ Backend below the floor: ${error.message}`);
|
|
412
|
+
const inputSchemas = parseInputSchemaMode(req.headers['cplace-schemas']);
|
|
413
|
+
if (!inputSchemas) {
|
|
414
|
+
debugLogWithTag('MCP', '❌ Invalid cplace-schemas header');
|
|
420
415
|
res.status(400).json({
|
|
421
416
|
jsonrpc: '2.0',
|
|
422
417
|
error: {
|
|
423
418
|
code: -32000,
|
|
424
|
-
message:
|
|
419
|
+
message: 'Bad Request: cplace-schemas must be "strict" or "standard"',
|
|
425
420
|
},
|
|
426
421
|
id: null,
|
|
427
422
|
});
|
|
428
423
|
return;
|
|
429
424
|
}
|
|
425
|
+
debugLogWithTag('MCP', `🆕 Creating new MCP session for ${new URL(cplaceUrl).hostname}`);
|
|
426
|
+
try {
|
|
427
|
+
sessionInfo = await createSession(cplaceUrl, apiToken, profilesHeader, inputSchemas);
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
if (!(error instanceof BelowFloorError))
|
|
431
|
+
throw error;
|
|
432
|
+
debugLogWithTag('MCP', `❌ Backend below the floor: ${error.message}`);
|
|
433
|
+
res.status(400).json(floorRefusalBody(error));
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
430
436
|
}
|
|
431
437
|
else {
|
|
432
438
|
debugLogWithTag('MCP', '❌ Invalid request: No valid session ID provided');
|
|
@@ -446,9 +452,15 @@ function startHttpServer() {
|
|
|
446
452
|
app.post('/', handlePostRequest);
|
|
447
453
|
const handleSessionRequest = async (req, res) => {
|
|
448
454
|
const sessionId = req.headers['mcp-session-id'];
|
|
449
|
-
if (!sessionId
|
|
450
|
-
debugLogWithTag('MCP', `❌
|
|
451
|
-
res.status(
|
|
455
|
+
if (!sessionId) {
|
|
456
|
+
debugLogWithTag('MCP', `❌ ${req.method} without a session ID`);
|
|
457
|
+
res.status(MISSING_SESSION_ID.status).json(MISSING_SESSION_ID.body);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (!sessions[sessionId]) {
|
|
461
|
+
counters.unknownSessionResponses++;
|
|
462
|
+
debugLogWithTag('MCP', `❌ Session not found: ${sessionId}`);
|
|
463
|
+
res.status(UNKNOWN_SESSION.status).json(UNKNOWN_SESSION.body);
|
|
452
464
|
return;
|
|
453
465
|
}
|
|
454
466
|
const sessionInfo = sessions[sessionId];
|
|
@@ -506,10 +518,18 @@ function startHttpServer() {
|
|
|
506
518
|
app.delete('/mcp', handleSessionRequest);
|
|
507
519
|
app.get('/', handleSessionRequest);
|
|
508
520
|
app.delete('/', handleSessionRequest);
|
|
509
|
-
app.listen(port, () => {
|
|
521
|
+
const httpServer = app.listen(port, () => {
|
|
510
522
|
debugLogWithTag('MCP', `🚀 Remote MCP server running on http://localhost:${port}`);
|
|
511
523
|
debugLogWithTag('MCP', `📡 MCP endpoint: http://localhost:${port}/mcp`);
|
|
512
524
|
debugLogWithTag('MCP', `🔧 Session management enabled with streamable-HTTP transport`);
|
|
513
525
|
});
|
|
526
|
+
const shutdown = (signal) => {
|
|
527
|
+
debugLogWithTag('MCP', `🛑 ${signal} received, shutting down`);
|
|
528
|
+
clearInterval(cleanupTimer);
|
|
529
|
+
httpServer.close();
|
|
530
|
+
process.exit(0);
|
|
531
|
+
};
|
|
532
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
533
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
514
534
|
}
|
|
515
535
|
//# sourceMappingURL=index.js.map
|