Skip to content

Commit 12144cf

Browse files
committed
docs(mcp): restore TSDoc that documented intent on exported types/methods
Earlier comment-trim pass went too far on a few exports — restored the TSDoc that explained non-obvious "why" decisions: - SimMcpOauthProviderInit.preregistered: when set, the SDK skips DCR. - McpServerConfig.userId: required for OAuth; selects which user's stored tokens to use. - McpOauthAuthorizationRequiredError: benign pending state vs failure. - McpToolsChangedCallback / McpClientOptions: notification semantics, DNS-rebinding pinning rationale, OAuth provider contract. - StoredMcpToolReference / StoredMcpTool: minimal vs extended use. - McpClient.connect: documents listChanged handler registration. - McpService.executeTool: documents session-error retry behavior. Pure-restatement comments ("Disconnect from MCP server") stay trimmed.
1 parent 4c05f63 commit 12144cf

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

apps/sim/lib/mcp/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export class McpClient {
8080
)
8181
}
8282

83+
/**
84+
* Initialize connection to MCP server.
85+
* If an `onToolsChanged` callback was provided, registers a notification handler
86+
* for `notifications/tools/list_changed` after connecting.
87+
*/
8388
async connect(): Promise<void> {
8489
logger.info(`Connecting to MCP server: ${this.config.name} (${this.config.transport})`)
8590

apps/sim/lib/mcp/oauth/provider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ export interface PreregisteredClient {
4141
interface SimMcpOauthProviderInit {
4242
row: McpOauthRow
4343
scope?: string
44-
/** When set, the SDK skips Dynamic Client Registration and uses these credentials directly. */
44+
/**
45+
* Optional user-supplied client credentials. When provided, the SDK skips
46+
* Dynamic Client Registration and uses these for the auth/token exchange.
47+
*/
4548
preregistered?: PreregisteredClient
4649
}
4750

apps/sim/lib/mcp/service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ class McpService {
242242
})
243243
}
244244

245+
/**
246+
* Execute a tool on a specific server with retry logic for session errors.
247+
* Retries once on session-related errors (400, 404, session ID issues).
248+
*/
245249
async executeTool(
246250
userId: string,
247251
serverId: string,

apps/sim/lib/mcp/types.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export interface McpServerConfig {
1717
transport: McpTransport
1818
url?: string
1919
authType?: McpAuthType
20-
/** Required for `authType === 'oauth'` — selects whose stored tokens to use. */
20+
/**
21+
* Required when `authType === 'oauth'` — identifies whose stored tokens
22+
* to use when establishing the connection. Omit for header / none auth.
23+
*/
2124
userId?: string
2225
workspaceId?: string
2326
headers?: Record<string, string>
@@ -129,7 +132,12 @@ export class McpConnectionError extends McpError {
129132
}
130133
}
131134

132-
/** Benign "needs re-auth" state — distinct from a connection failure. */
135+
/**
136+
* Thrown when an OAuth-protected MCP server is reachable but the current
137+
* user has not yet authorized Sim. This is a benign "pending" state, not a
138+
* connection failure — callers should surface a re-auth prompt rather than
139+
* marking the server as errored.
140+
*/
133141
export class McpOauthAuthorizationRequiredError extends McpError {
134142
constructor(
135143
public readonly serverId: string,
@@ -153,15 +161,32 @@ export interface McpServerSummary {
153161
error?: string
154162
}
155163

164+
/**
165+
* Callback invoked when an MCP server sends a `notifications/tools/list_changed` notification.
166+
*/
156167
export type McpToolsChangedCallback = (serverId: string) => void
157168

169+
/**
170+
* Options for creating an McpClient with notification support.
171+
*/
158172
export interface McpClientOptions {
159173
config: McpServerConfig
160174
securityPolicy?: McpSecurityPolicy
161175
onToolsChanged?: McpToolsChangedCallback
162-
/** Pre-resolved IP pinned via undici to prevent DNS-rebinding between URL validation and connection. */
176+
/**
177+
* Pre-resolved IP address to pin all transport HTTP connections to. When
178+
* set, the SDK transport uses a custom fetch backed by an undici Agent with
179+
* a fixed DNS lookup, preventing DNS-rebinding (TOCTOU) attacks between
180+
* URL validation and connection. Should be supplied by callers that have
181+
* just validated the URL via `validateMcpServerSsrf`.
182+
*/
163183
resolvedIP?: string
164-
/** SDK provider for OAuth token discovery, refresh, and 401 recovery. Required for `authType === 'oauth'`. */
184+
/**
185+
* SDK-compatible OAuth client provider. When provided, the underlying
186+
* StreamableHTTPClientTransport delegates token discovery, refresh, and
187+
* 401 recovery to it. Should be supplied for `authType === 'oauth'`
188+
* server configs.
189+
*/
165190
authProvider?: import('@modelcontextprotocol/sdk/client/auth.js').OAuthClientProvider
166191
}
167192

@@ -200,14 +225,21 @@ export interface McpToolDiscoveryResponse {
200225
byServer: Record<string, number>
201226
}
202227

203-
/** Minimal MCP tool reference stored in workflow blocks for schema validation. */
228+
/**
229+
* MCP tool reference stored in workflow blocks (for validation).
230+
* Minimal version used for comparing against discovered tools.
231+
*/
204232
export interface StoredMcpToolReference {
205233
serverId: string
206234
serverUrl?: string
207235
toolName: string
208236
schema?: McpToolSchema
209237
}
210238

239+
/**
240+
* Full stored MCP tool with workflow context (for API responses).
241+
* Extended version that includes which workflow the tool is used in.
242+
*/
211243
export interface StoredMcpTool extends StoredMcpToolReference {
212244
workflowId: string
213245
workflowName: string

0 commit comments

Comments
 (0)