Skip to content

Commit b4e8dcd

Browse files
committed
fix client example
1 parent bbafc85 commit b4e8dcd

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/examples/server/demoInMemoryOAuthProvider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export class DemoInMemoryAuthProvider implements OAuthServerProvider {
4444
const searchParams = new URLSearchParams({
4545
code,
4646
});
47+
if (params.state !== undefined) {
48+
searchParams.set('state', params.state);
49+
}
4750

4851
this.codes.set(code, {
4952
client,
@@ -102,7 +105,7 @@ export class DemoInMemoryAuthProvider implements OAuthServerProvider {
102105

103106
return {
104107
access_token: token,
105-
token_type: 'Bearer',
108+
token_type: 'bearer',
106109
expires_in: 3600,
107110
scope: (codeData.params.scopes || []).join(' '),
108111
};

src/examples/server/simpleStreamableHttp.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { randomUUID } from 'node:crypto';
33
import { z } from 'zod';
44
import { McpServer } from '../../server/mcp.js';
55
import { StreamableHTTPServerTransport } from '../../server/streamableHttp.js';
6-
import { mcpAuthRouter, mcpProtectedResourceRouter, getOAuthProtectedResourceMetadataUrl } from '../../server/auth/router.js';
6+
import { mcpAuthRouter, getOAuthProtectedResourceMetadataUrl } from '../../server/auth/router.js';
77
import { requireBearerAuth } from '../../server/auth/middleware/bearerAuth.js';
88
import { CallToolResult, GetPromptResult, isInitializeRequest, ReadResourceResult } from '../../types.js';
99
import { InMemoryEventStore } from '../shared/inMemoryEventStore.js';
@@ -188,7 +188,6 @@ if (useOAuth) {
188188
authApp.use(mcpAuthRouter({
189189
provider,
190190
issuerUrl: authServerUrl,
191-
baseUrl: authServerUrl,
192191
scopesSupported: ['mcp:tools'],
193192
// This endpoint is set up on the Authorization server, but really shouldn't be.
194193
protectedResourceOptions: {
@@ -202,12 +201,15 @@ if (useOAuth) {
202201
console.log(`OAuth Authorization Server listening on port ${AUTH_PORT}`);
203202
});
204203

205-
// Add protected resource metadata to the main MCP server
206-
app.use(mcpProtectedResourceRouter({
204+
// Add both resource metadata and oauth server metadata (for backwards compatiblity) to the main MCP server
205+
app.use(mcpAuthRouter({
206+
provider,
207207
issuerUrl: authServerUrl,
208-
serverUrl: mcpServerUrl,
209208
scopesSupported: ['mcp:tools'],
210-
resourceName: 'MCP Demo Server',
209+
protectedResourceOptions: {
210+
serverUrl: mcpServerUrl,
211+
resourceName: 'MCP Demo Server',
212+
},
211213
}));
212214

213215
authMiddleware = requireBearerAuth({

0 commit comments

Comments
 (0)