@apicircle/mcp-server 1.0.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.
@@ -0,0 +1,160 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
3
+ import { z } from 'zod';
4
+ import { WorkspaceSynced, WorkspaceLocal, MockServer, MockRuntimeEntry, McpToolName } from '@apicircle/shared';
5
+ import { WorkspaceState, WorkspacePatch } from '@apicircle/core';
6
+
7
+ interface WorkspaceProvider {
8
+ /** Snapshot the current `{ synced, local }` pair. */
9
+ read(): Promise<WorkspaceState>;
10
+ /**
11
+ * Apply a single mutation. Returns the resulting state + the ids the
12
+ * patch touched, so the tool handler can echo a meaningful response back
13
+ * to the AI client (e.g. "created request `r-abc`").
14
+ */
15
+ apply(patch: WorkspacePatch): Promise<{
16
+ state: WorkspaceState;
17
+ changedIds: string[];
18
+ }>;
19
+ /**
20
+ * Bulk overwrite. Used by `workspace.write` (rare — most edits go
21
+ * through `apply`). Implementations should accept a partial pair so
22
+ * tools targeting only synced or only local can leave the other side
23
+ * untouched.
24
+ */
25
+ write(next: {
26
+ synced?: WorkspaceSynced;
27
+ local?: WorkspaceLocal;
28
+ }): Promise<WorkspaceState>;
29
+ }
30
+
31
+ interface StartMockResult {
32
+ port: number;
33
+ pid: number | null;
34
+ startedAt: string;
35
+ }
36
+ interface MockController {
37
+ start(server: MockServer, opts?: {
38
+ port?: number;
39
+ }): Promise<StartMockResult>;
40
+ stop(serverId: string): Promise<void>;
41
+ /** Snapshot of currently running mocks. */
42
+ list(): Promise<Array<{
43
+ serverId: string;
44
+ runtime: MockRuntimeEntry;
45
+ }>>;
46
+ }
47
+
48
+ interface ToolHandlerContext {
49
+ workspace: WorkspaceProvider;
50
+ mock: MockController;
51
+ }
52
+ interface ToolDef<S extends z.ZodTypeAny = z.ZodTypeAny> {
53
+ name: McpToolName;
54
+ description: string;
55
+ inputSchema: S;
56
+ handler: (input: z.infer<S>, ctx: ToolHandlerContext) => Promise<unknown>;
57
+ }
58
+ type AnyToolDef = ToolDef<z.ZodTypeAny>;
59
+
60
+ interface McpHostOptions {
61
+ serverInfo?: {
62
+ name: string;
63
+ version: string;
64
+ };
65
+ context: ToolHandlerContext;
66
+ tools: AnyToolDef[];
67
+ }
68
+ declare class McpHost {
69
+ readonly server: McpServer;
70
+ private readonly tools;
71
+ private readonly context;
72
+ constructor(options: McpHostOptions);
73
+ private registerAll;
74
+ /** Connect the underlying server to a transport (defaults to stdio). */
75
+ connect(transport?: Transport): Promise<void>;
76
+ close(): Promise<void>;
77
+ }
78
+
79
+ declare const TOOL_REGISTRY: AnyToolDef[];
80
+ declare function getTool(name: McpToolName): AnyToolDef | undefined;
81
+
82
+ /**
83
+ * Pure in-memory provider. Used for unit tests and any programmatic
84
+ * embedding where the consumer already owns workspace state and just
85
+ * wants to drive the MCP tool catalog without disk or IPC.
86
+ */
87
+ declare class InMemoryWorkspaceProvider implements WorkspaceProvider {
88
+ private state;
89
+ constructor(initial: WorkspaceState);
90
+ read(): Promise<WorkspaceState>;
91
+ apply(patch: WorkspacePatch): Promise<{
92
+ state: WorkspaceState;
93
+ changedIds: string[];
94
+ }>;
95
+ write(next: {
96
+ synced?: WorkspaceSynced;
97
+ local?: WorkspaceLocal;
98
+ }): Promise<WorkspaceState>;
99
+ }
100
+
101
+ /**
102
+ * Disk-backed provider used by the standalone CLI and the headless MCP
103
+ * server when launched outside Electron. Each `apply` runs a full
104
+ * load → mutate → save cycle under a `proper-lockfile` advisory lock so
105
+ * concurrent writers (a second CLI invocation, the desktop app on the
106
+ * same workspace) can't clobber each other.
107
+ */
108
+ declare class FileBackedWorkspaceProvider implements WorkspaceProvider {
109
+ private readonly dir;
110
+ constructor(dir: string);
111
+ read(): Promise<WorkspaceState>;
112
+ apply(patch: WorkspacePatch): Promise<{
113
+ state: WorkspaceState;
114
+ changedIds: string[];
115
+ }>;
116
+ write(next: {
117
+ synced?: WorkspaceSynced;
118
+ local?: WorkspaceLocal;
119
+ }): Promise<WorkspaceState>;
120
+ }
121
+
122
+ /**
123
+ * MockController implementation that owns its mock processes directly via
124
+ * `@apicircle/mock-server-core`. Used by the CLI and any embedder that
125
+ * wants the simplest possible setup. The desktop app supplies a
126
+ * different controller (process-bridge to its main process) so renderer-
127
+ * side state stays consistent.
128
+ */
129
+ declare class InProcessMockController implements MockController {
130
+ private readonly handles;
131
+ private readonly meta;
132
+ start(server: MockServer, opts?: {
133
+ port?: number;
134
+ }): Promise<StartMockResult>;
135
+ stop(serverId: string): Promise<void>;
136
+ list(): Promise<Array<{
137
+ serverId: string;
138
+ runtime: MockRuntimeEntry;
139
+ }>>;
140
+ }
141
+
142
+ interface CreateMcpServerOptions {
143
+ workspace: WorkspaceProvider;
144
+ mock: MockController;
145
+ /** Override the registered tool list. Defaults to `TOOL_REGISTRY`. */
146
+ tools?: AnyToolDef[];
147
+ serverInfo?: {
148
+ name: string;
149
+ version: string;
150
+ };
151
+ }
152
+ /**
153
+ * Build a fully-wired McpHost ready to `await host.connect()` over stdio.
154
+ * Tool implementations come from `TOOL_REGISTRY` by default; pass `tools`
155
+ * to inject a curated subset (useful for tests or for hosting only the
156
+ * import surface).
157
+ */
158
+ declare function createMcpServer(options: CreateMcpServerOptions): McpHost;
159
+
160
+ export { type AnyToolDef, type CreateMcpServerOptions, FileBackedWorkspaceProvider, InMemoryWorkspaceProvider, InProcessMockController, McpHost, type MockController, type StartMockResult, TOOL_REGISTRY, type ToolDef, type ToolHandlerContext, type WorkspaceProvider, createMcpServer, getTool };