@apicircle/mcp-server 1.0.1 → 1.0.3

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/index.d.cts CHANGED
@@ -3,6 +3,7 @@ import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
3
3
  import { z } from 'zod';
4
4
  import { WorkspaceSynced, WorkspaceLocal, MockServer, MockRuntimeEntry, McpToolName } from '@apicircle/shared';
5
5
  import { WorkspaceState, WorkspacePatch } from '@apicircle/core';
6
+ import { WorkspaceRegistry } from '@apicircle/core/workspace/registry';
6
7
 
7
8
  interface WorkspaceProvider {
8
9
  /** Snapshot the current `{ synced, local }` pair. */
@@ -45,8 +46,59 @@ interface MockController {
45
46
  }>>;
46
47
  }
47
48
 
49
+ interface WorkspaceSummary {
50
+ id: string;
51
+ name: string;
52
+ isActive: boolean;
53
+ /** ISO timestamps surfaced from the on-disk registry entry. */
54
+ createdAt: string;
55
+ lastOpenedAt: string;
56
+ /** Cheap counts populated when the summary is built so AI clients can
57
+ * decide which workspace to drill into without a second tool call.
58
+ * May be `null` if the per-workspace doc couldn't be read. */
59
+ counts: {
60
+ requests: number;
61
+ folders: number;
62
+ environments: number;
63
+ mockServers: number;
64
+ plans: number;
65
+ } | null;
66
+ }
67
+ interface Workspaces {
68
+ /** Enumerate every workspace + which is currently active. */
69
+ list(): Promise<WorkspaceSummary[]>;
70
+ /** Return a `WorkspaceProvider` scoped to a specific workspace id. */
71
+ for(workspaceId: string): WorkspaceProvider;
72
+ /** id of the workspace that `ctx.workspace` currently points at. */
73
+ activeId(): string | null;
74
+ /** Switch which workspace `ctx.workspace` resolves to. */
75
+ setActive(workspaceId: string): Promise<void>;
76
+ }
77
+ /**
78
+ * Trivial single-workspace adapter — wraps an existing `WorkspaceProvider`
79
+ * so legacy single-dir hosts can still answer `list()` and `for()` calls.
80
+ * `list()` returns one entry (the active workspace itself); `for(id)` is a
81
+ * passthrough that asserts the id matches.
82
+ */
83
+ declare class SingleWorkspaceAdapter implements Workspaces {
84
+ private readonly provider;
85
+ private workspaceId;
86
+ private readonly displayName;
87
+ constructor(provider: WorkspaceProvider, workspaceId: string | null, displayName?: string);
88
+ list(): Promise<WorkspaceSummary[]>;
89
+ for(workspaceId: string): WorkspaceProvider;
90
+ activeId(): string | null;
91
+ setActive(workspaceId: string): Promise<void>;
92
+ }
93
+ declare class WorkspaceNotFoundError extends Error {
94
+ readonly code: "workspace-not-found";
95
+ readonly workspaceId: string;
96
+ constructor(workspaceId: string);
97
+ }
98
+
48
99
  interface ToolHandlerContext {
49
100
  workspace: WorkspaceProvider;
101
+ workspaces: Workspaces;
50
102
  mock: MockController;
51
103
  }
52
104
  interface ToolDef<S extends z.ZodTypeAny = z.ZodTypeAny> {
@@ -119,6 +171,30 @@ declare class FileBackedWorkspaceProvider implements WorkspaceProvider {
119
171
  }): Promise<WorkspaceState>;
120
172
  }
121
173
 
174
+ declare class MultiWorkspaceProvider implements Workspaces {
175
+ private readonly registryRoot;
176
+ private active;
177
+ private activeWorkspaceId;
178
+ constructor(registryRoot: string);
179
+ /**
180
+ * Hydrate the active provider from disk. Must be called once before the
181
+ * MCP host boots so `ctx.workspace.read()` doesn't race the first
182
+ * registry-load. Returns the registry the boot can log.
183
+ */
184
+ init(): Promise<WorkspaceRegistry>;
185
+ /** The provider tool handlers see as `ctx.workspace`. */
186
+ activeProvider(): WorkspaceProvider;
187
+ list(): Promise<WorkspaceSummary[]>;
188
+ for(workspaceId: string): WorkspaceProvider;
189
+ activeId(): string | null;
190
+ setActive(workspaceId: string): Promise<void>;
191
+ /**
192
+ * Idempotent registry write — used by tests / tools that need to
193
+ * persist registry updates that didn't go through `setActive`.
194
+ */
195
+ writeRegistry(registry: WorkspaceRegistry): Promise<void>;
196
+ }
197
+
122
198
  /**
123
199
  * MockController implementation that owns its mock processes directly via
124
200
  * `@apicircle/mock-server-core`. Used by the CLI and any embedder that
@@ -140,7 +216,18 @@ declare class InProcessMockController implements MockController {
140
216
  }
141
217
 
142
218
  interface CreateMcpServerOptions {
219
+ /**
220
+ * Provider for the ACTIVE workspace. Tools that consume `ctx.workspace`
221
+ * see this directly. When you pass a `MultiWorkspaceProvider`, use its
222
+ * `activeProvider()` here.
223
+ */
143
224
  workspace: WorkspaceProvider;
225
+ /**
226
+ * Optional multi-workspace surface. When omitted, the host wraps
227
+ * `workspace` in a `SingleWorkspaceAdapter` so `workspace.list` and the
228
+ * multi-workspace envelope still work (with one entry).
229
+ */
230
+ workspaces?: Workspaces;
144
231
  mock: MockController;
145
232
  /** Override the registered tool list. Defaults to `TOOL_REGISTRY`. */
146
233
  tools?: AnyToolDef[];
@@ -157,4 +244,4 @@ interface CreateMcpServerOptions {
157
244
  */
158
245
  declare function createMcpServer(options: CreateMcpServerOptions): McpHost;
159
246
 
160
- export { type AnyToolDef, type CreateMcpServerOptions, FileBackedWorkspaceProvider, InMemoryWorkspaceProvider, InProcessMockController, McpHost, type MockController, type StartMockResult, TOOL_REGISTRY, type ToolDef, type ToolHandlerContext, type WorkspaceProvider, createMcpServer, getTool };
247
+ export { type AnyToolDef, type CreateMcpServerOptions, FileBackedWorkspaceProvider, InMemoryWorkspaceProvider, InProcessMockController, McpHost, type MockController, MultiWorkspaceProvider, SingleWorkspaceAdapter, type StartMockResult, TOOL_REGISTRY, type ToolDef, type ToolHandlerContext, WorkspaceNotFoundError, type WorkspaceProvider, type WorkspaceSummary, type Workspaces, createMcpServer, getTool };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
3
3
  import { z } from 'zod';
4
4
  import { WorkspaceSynced, WorkspaceLocal, MockServer, MockRuntimeEntry, McpToolName } from '@apicircle/shared';
5
5
  import { WorkspaceState, WorkspacePatch } from '@apicircle/core';
6
+ import { WorkspaceRegistry } from '@apicircle/core/workspace/registry';
6
7
 
7
8
  interface WorkspaceProvider {
8
9
  /** Snapshot the current `{ synced, local }` pair. */
@@ -45,8 +46,59 @@ interface MockController {
45
46
  }>>;
46
47
  }
47
48
 
49
+ interface WorkspaceSummary {
50
+ id: string;
51
+ name: string;
52
+ isActive: boolean;
53
+ /** ISO timestamps surfaced from the on-disk registry entry. */
54
+ createdAt: string;
55
+ lastOpenedAt: string;
56
+ /** Cheap counts populated when the summary is built so AI clients can
57
+ * decide which workspace to drill into without a second tool call.
58
+ * May be `null` if the per-workspace doc couldn't be read. */
59
+ counts: {
60
+ requests: number;
61
+ folders: number;
62
+ environments: number;
63
+ mockServers: number;
64
+ plans: number;
65
+ } | null;
66
+ }
67
+ interface Workspaces {
68
+ /** Enumerate every workspace + which is currently active. */
69
+ list(): Promise<WorkspaceSummary[]>;
70
+ /** Return a `WorkspaceProvider` scoped to a specific workspace id. */
71
+ for(workspaceId: string): WorkspaceProvider;
72
+ /** id of the workspace that `ctx.workspace` currently points at. */
73
+ activeId(): string | null;
74
+ /** Switch which workspace `ctx.workspace` resolves to. */
75
+ setActive(workspaceId: string): Promise<void>;
76
+ }
77
+ /**
78
+ * Trivial single-workspace adapter — wraps an existing `WorkspaceProvider`
79
+ * so legacy single-dir hosts can still answer `list()` and `for()` calls.
80
+ * `list()` returns one entry (the active workspace itself); `for(id)` is a
81
+ * passthrough that asserts the id matches.
82
+ */
83
+ declare class SingleWorkspaceAdapter implements Workspaces {
84
+ private readonly provider;
85
+ private workspaceId;
86
+ private readonly displayName;
87
+ constructor(provider: WorkspaceProvider, workspaceId: string | null, displayName?: string);
88
+ list(): Promise<WorkspaceSummary[]>;
89
+ for(workspaceId: string): WorkspaceProvider;
90
+ activeId(): string | null;
91
+ setActive(workspaceId: string): Promise<void>;
92
+ }
93
+ declare class WorkspaceNotFoundError extends Error {
94
+ readonly code: "workspace-not-found";
95
+ readonly workspaceId: string;
96
+ constructor(workspaceId: string);
97
+ }
98
+
48
99
  interface ToolHandlerContext {
49
100
  workspace: WorkspaceProvider;
101
+ workspaces: Workspaces;
50
102
  mock: MockController;
51
103
  }
52
104
  interface ToolDef<S extends z.ZodTypeAny = z.ZodTypeAny> {
@@ -119,6 +171,30 @@ declare class FileBackedWorkspaceProvider implements WorkspaceProvider {
119
171
  }): Promise<WorkspaceState>;
120
172
  }
121
173
 
174
+ declare class MultiWorkspaceProvider implements Workspaces {
175
+ private readonly registryRoot;
176
+ private active;
177
+ private activeWorkspaceId;
178
+ constructor(registryRoot: string);
179
+ /**
180
+ * Hydrate the active provider from disk. Must be called once before the
181
+ * MCP host boots so `ctx.workspace.read()` doesn't race the first
182
+ * registry-load. Returns the registry the boot can log.
183
+ */
184
+ init(): Promise<WorkspaceRegistry>;
185
+ /** The provider tool handlers see as `ctx.workspace`. */
186
+ activeProvider(): WorkspaceProvider;
187
+ list(): Promise<WorkspaceSummary[]>;
188
+ for(workspaceId: string): WorkspaceProvider;
189
+ activeId(): string | null;
190
+ setActive(workspaceId: string): Promise<void>;
191
+ /**
192
+ * Idempotent registry write — used by tests / tools that need to
193
+ * persist registry updates that didn't go through `setActive`.
194
+ */
195
+ writeRegistry(registry: WorkspaceRegistry): Promise<void>;
196
+ }
197
+
122
198
  /**
123
199
  * MockController implementation that owns its mock processes directly via
124
200
  * `@apicircle/mock-server-core`. Used by the CLI and any embedder that
@@ -140,7 +216,18 @@ declare class InProcessMockController implements MockController {
140
216
  }
141
217
 
142
218
  interface CreateMcpServerOptions {
219
+ /**
220
+ * Provider for the ACTIVE workspace. Tools that consume `ctx.workspace`
221
+ * see this directly. When you pass a `MultiWorkspaceProvider`, use its
222
+ * `activeProvider()` here.
223
+ */
143
224
  workspace: WorkspaceProvider;
225
+ /**
226
+ * Optional multi-workspace surface. When omitted, the host wraps
227
+ * `workspace` in a `SingleWorkspaceAdapter` so `workspace.list` and the
228
+ * multi-workspace envelope still work (with one entry).
229
+ */
230
+ workspaces?: Workspaces;
144
231
  mock: MockController;
145
232
  /** Override the registered tool list. Defaults to `TOOL_REGISTRY`. */
146
233
  tools?: AnyToolDef[];
@@ -157,4 +244,4 @@ interface CreateMcpServerOptions {
157
244
  */
158
245
  declare function createMcpServer(options: CreateMcpServerOptions): McpHost;
159
246
 
160
- export { type AnyToolDef, type CreateMcpServerOptions, FileBackedWorkspaceProvider, InMemoryWorkspaceProvider, InProcessMockController, McpHost, type MockController, type StartMockResult, TOOL_REGISTRY, type ToolDef, type ToolHandlerContext, type WorkspaceProvider, createMcpServer, getTool };
247
+ export { type AnyToolDef, type CreateMcpServerOptions, FileBackedWorkspaceProvider, InMemoryWorkspaceProvider, InProcessMockController, McpHost, type MockController, MultiWorkspaceProvider, SingleWorkspaceAdapter, type StartMockResult, TOOL_REGISTRY, type ToolDef, type ToolHandlerContext, WorkspaceNotFoundError, type WorkspaceProvider, type WorkspaceSummary, type Workspaces, createMcpServer, getTool };