-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathgroup.ts
More file actions
198 lines (177 loc) · 6.67 KB
/
Copy pathgroup.ts
File metadata and controls
198 lines (177 loc) · 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import { HttpApiEndpoint, HttpApiGroup } from "effect/unstable/httpapi";
import { Schema } from "effect";
import {
IntegrationSlug,
InternalError,
IntegrationAlreadyExistsError,
IntegrationNotFoundError,
} from "@executor-js/sdk/shared";
import { McpConnectionError, McpToolDiscoveryError } from "../sdk/errors";
import {
McpAuthMethod,
McpAuthMethodInput,
McpAuthShorthand,
McpIntegrationConfig,
} from "../sdk/types";
// ---------------------------------------------------------------------------
// Params
// ---------------------------------------------------------------------------
const SlugParams = { slug: IntegrationSlug };
const StringMap = Schema.Record(Schema.String, Schema.String);
const IntegrationNotFound = IntegrationNotFoundError.annotate({ httpApiStatus: 404 });
// ---------------------------------------------------------------------------
// Add server — discriminated union on transport. An MCP server is registered
// as an integration; connections (credentials) are created separately through
// the core connections / oauth surface.
// ---------------------------------------------------------------------------
const AddRemoteServerPayload = Schema.Struct({
transport: Schema.optional(Schema.Literal("remote")),
name: Schema.String,
/** Agent-visible catalog description. Defaults to the display name. */
description: Schema.optional(Schema.String),
endpoint: Schema.String,
remoteTransport: Schema.optional(Schema.Literals(["streamable-http", "sse", "auto"])),
slug: Schema.optional(Schema.String),
queryParams: Schema.optional(StringMap),
headers: Schema.optional(StringMap),
/** Declared auth methods a connection can be applied through. */
authenticationTemplate: Schema.optional(Schema.Array(McpAuthMethodInput)),
/** Single-method shorthand (legacy callers); ignored when
* `authenticationTemplate` is present. */
auth: Schema.optional(McpAuthShorthand),
});
const AddStdioServerPayload = Schema.Struct({
transport: Schema.Literal("stdio"),
name: Schema.String,
description: Schema.optional(Schema.String),
command: Schema.String,
args: Schema.optional(Schema.Array(Schema.String)),
/** Declare the secret env vars this server needs, by name. Their values are
* supplied as the connection's secrets. */
envVars: Schema.optional(Schema.Array(Schema.String)),
/** Static, non-credential environment variables injected into the subprocess. */
env: Schema.optional(StringMap),
cwd: Schema.optional(Schema.String),
slug: Schema.optional(Schema.String),
});
const AddServerPayload = Schema.Union([AddRemoteServerPayload, AddStdioServerPayload]);
const ProbeEndpointPayload = Schema.Struct({
endpoint: Schema.String,
headers: Schema.optional(StringMap),
queryParams: Schema.optional(StringMap),
});
const ProbeEndpointResponse = Schema.Struct({
connected: Schema.Boolean,
requiresAuthentication: Schema.Boolean,
requiresOAuth: Schema.Boolean,
supportsDynamicRegistration: Schema.Boolean,
name: Schema.String,
slug: Schema.String,
toolCount: Schema.NullOr(Schema.Number),
serverName: Schema.NullOr(Schema.String),
/** Server `instructions` from initialize — prefills the description field. */
instructions: Schema.NullOr(Schema.String),
});
// ---------------------------------------------------------------------------
// Responses
// ---------------------------------------------------------------------------
const AddServerResponse = Schema.Struct({
slug: Schema.String,
});
const RemoveServerResponse = Schema.Struct({
removed: Schema.Boolean,
});
const ConfigureServerPayload = Schema.Struct({
config: McpIntegrationConfig,
});
const ConfigureServerResponse = Schema.Struct({
config: McpIntegrationConfig,
toolsRefreshFailed: Schema.Boolean,
});
const RefreshServerToolsResponse = Schema.Struct({
toolsRefreshFailed: Schema.Boolean,
});
// The configureAuth payload/response — custom auth methods to merge-append
// onto the integration's `authenticationTemplate` (or `replace` the set).
// Mirrors the GraphQL/OpenAPI configure endpoints.
const ConfigureAuthPayload = Schema.Struct({
authenticationTemplate: Schema.Array(McpAuthMethodInput),
mode: Schema.optional(Schema.Literals(["merge", "replace"])),
});
const ConfigureAuthResponse = Schema.Struct({
authenticationTemplate: Schema.Array(McpAuthMethod),
});
const GetServerResponse = Schema.NullOr(
Schema.Struct({
slug: IntegrationSlug,
description: Schema.String,
kind: Schema.String,
canRemove: Schema.Boolean,
canRefresh: Schema.Boolean,
config: McpIntegrationConfig,
}),
);
// ---------------------------------------------------------------------------
// Group
//
// Integrations are tenant-level (no scope segment); plugin domain errors carry
// their own `HttpApiSchema` status (4xx). `InternalError` is the shared opaque
// 500 translated at the HTTP edge.
// ---------------------------------------------------------------------------
export const McpGroup = HttpApiGroup.make("mcp")
.add(
HttpApiEndpoint.post("probeEndpoint", "/mcp/probe", {
payload: ProbeEndpointPayload,
success: ProbeEndpointResponse,
error: [InternalError, McpConnectionError, McpToolDiscoveryError],
}),
)
.add(
HttpApiEndpoint.post("addServer", "/mcp/servers", {
payload: AddServerPayload,
success: AddServerResponse,
error: [
InternalError,
McpConnectionError,
McpToolDiscoveryError,
IntegrationAlreadyExistsError,
],
}),
)
.add(
HttpApiEndpoint.delete("removeServer", "/mcp/servers/:slug", {
params: SlugParams,
success: RemoveServerResponse,
error: [InternalError, McpConnectionError, McpToolDiscoveryError],
}),
)
.add(
HttpApiEndpoint.get("getServer", "/mcp/servers/:slug", {
params: SlugParams,
success: GetServerResponse,
error: [InternalError, McpConnectionError, McpToolDiscoveryError],
}),
)
.add(
HttpApiEndpoint.post("configureServer", "/mcp/servers/:slug/config", {
params: SlugParams,
payload: ConfigureServerPayload,
success: ConfigureServerResponse,
error: [InternalError, McpConnectionError, McpToolDiscoveryError, IntegrationNotFound],
}),
)
.add(
HttpApiEndpoint.post("refreshServerTools", "/mcp/servers/:slug/tools/refresh", {
params: SlugParams,
success: RefreshServerToolsResponse,
error: [InternalError, McpConnectionError, McpToolDiscoveryError, IntegrationNotFound],
}),
)
.add(
HttpApiEndpoint.post("configureAuth", "/mcp/servers/:slug/auth", {
params: SlugParams,
payload: ConfigureAuthPayload,
success: ConfigureAuthResponse,
error: [InternalError, McpConnectionError, McpToolDiscoveryError],
}),
);