Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/client/src/client/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,28 +763,31 @@ async function authInternal(

// Handle token refresh or new authorization
if (tokens?.refresh_token) {
let newTokens;
try {
// Attempt to refresh the token
const newTokens = await refreshAuthorization(authorizationServerUrl, {
newTokens = await refreshAuthorization(authorizationServerUrl, {
metadata,
clientInformation,
refreshToken: tokens.refresh_token,
resource,
addClientAuthentication: provider.addClientAuthentication,
fetchFn
});

await provider.saveTokens(newTokens);
return 'AUTHORIZED';
} catch (error) {
// If this is a ServerError, or an unknown type, log it out and try to continue. Otherwise, escalate so we can fix things and retry.
if (!(error instanceof OAuthError) || error.code === OAuthErrorCode.ServerError) {
// Could not refresh OAuth tokens
// Could not refresh OAuth tokens — fall through to re-auth
} else {
// Refresh failed for another reason, re-throw
throw error;
}
}

if (newTokens) {
await provider.saveTokens(newTokens); // Let I/O errors propagate
return 'AUTHORIZED';
}
}

const state = provider.state ? await provider.state() : undefined;
Expand Down
13 changes: 12 additions & 1 deletion packages/server/src/server/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
CreateTaskResult,
CreateTaskServerContext,
GetPromptResult,
Icon,
Implementation,
ListPromptsResult,
ListResourcesResult,
Expand Down Expand Up @@ -533,6 +534,7 @@ export class McpServer {
title: prompt.title,
description: prompt.description,
arguments: prompt.argsSchema ? promptArgumentsFromStandardSchema(prompt.argsSchema) : undefined,
icons: prompt.icons,
_meta: prompt._meta
};
})
Expand Down Expand Up @@ -702,6 +704,7 @@ export class McpServer {
title: string | undefined,
description: string | undefined,
argsSchema: StandardSchemaWithJSON | undefined,
icons: Icon[] | undefined,
callback: PromptCallback<StandardSchemaWithJSON | undefined>,
_meta: Record<string, unknown> | undefined
): RegisteredPrompt {
Expand All @@ -713,6 +716,7 @@ export class McpServer {
title,
description,
argsSchema,
icons,
_meta,
handler: createPromptHandler(name, argsSchema, callback),
enabled: true,
Expand All @@ -726,6 +730,7 @@ export class McpServer {
}
if (updates.title !== undefined) registeredPrompt.title = updates.title;
if (updates.description !== undefined) registeredPrompt.description = updates.description;
if (updates.icons !== undefined) registeredPrompt.icons = updates.icons;
if (updates._meta !== undefined) registeredPrompt._meta = updates._meta;

// Track if we need to regenerate the handler
Expand Down Expand Up @@ -952,6 +957,7 @@ export class McpServer {
title?: string;
description?: string;
argsSchema?: Args;
icons?: Icon[];
_meta?: Record<string, unknown>;
},
cb: PromptCallback<Args>
Expand All @@ -963,6 +969,7 @@ export class McpServer {
title?: string;
description?: string;
argsSchema?: Args;
icons?: Icon[];
_meta?: Record<string, unknown>;
},
cb: LegacyPromptCallback<Args>
Expand All @@ -973,6 +980,7 @@ export class McpServer {
title?: string;
description?: string;
argsSchema?: StandardSchemaWithJSON | ZodRawShape;
icons?: Icon[];
_meta?: Record<string, unknown>;
},
cb: PromptCallback<StandardSchemaWithJSON> | LegacyPromptCallback<ZodRawShape>
Expand All @@ -981,13 +989,14 @@ export class McpServer {
throw new Error(`Prompt ${name} is already registered`);
}

const { title, description, argsSchema, _meta } = config;
const { title, description, argsSchema, icons, _meta } = config;

const registeredPrompt = this._createRegisteredPrompt(
name,
title,
description,
normalizeRawShapeSchema(argsSchema),
icons,
cb as PromptCallback<StandardSchemaWithJSON | undefined>,
_meta
);
Expand Down Expand Up @@ -1308,6 +1317,7 @@ export type RegisteredPrompt = {
title?: string;
description?: string;
argsSchema?: StandardSchemaWithJSON;
icons?: Icon[];
_meta?: Record<string, unknown>;
/** @hidden */
handler: PromptHandler;
Expand All @@ -1319,6 +1329,7 @@ export type RegisteredPrompt = {
title?: string;
description?: string;
argsSchema?: Args;
icons?: Icon[];
_meta?: Record<string, unknown>;
callback?: PromptCallback<Args>;
enabled?: boolean;
Expand Down
Loading