Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
186 changes: 185 additions & 1 deletion apps/api/src/__tests__/route-policy-enforcement.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apps/api/src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export { trpc } from './trpc';
// mcp
export { mcp } from './mcp';
export { mcpRouting } from './mcp/routing';
export { mcpOAuthMetadata } from './mcp-oauth';
export { publicRoomoteMcp } from './mcp/roomote';

// inference gateway
export { inference } from './inference';
Expand Down
36 changes: 36 additions & 0 deletions apps/api/src/handlers/mcp-oauth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Hono, type Context } from 'hono';

import { getRoomoteMcpResourceUrl, ROOMOTE_MCP_SCOPE } from '@roomote/auth';
import { Env } from '@roomote/env';

import type { Variables } from '../types';

const ROOMOTE_MCP_PROTECTED_RESOURCE_METADATA_PATH =
'/.well-known/oauth-protected-resource/mcp';
const LEGACY_ROOMOTE_MCP_PROTECTED_RESOURCE_METADATA_PATH =
'/.well-known/oauth-protected-resource/api/mcp-routing/roomote';

export const mcpOAuthMetadata = new Hono<{ Variables: Variables }>();

const protectedResourceMetadataHandler = (
c: Context<{ Variables: Variables }>,
) => {
const authorizationServer = Env.R_PUBLIC_URL ?? Env.R_APP_URL;

c.header('Cache-Control', 'public, max-age=3600');
return c.json({
resource: getRoomoteMcpResourceUrl(Env.TRPC_URL),
authorization_servers: [new URL(authorizationServer).origin],
bearer_methods_supported: ['header'],
scopes_supported: [ROOMOTE_MCP_SCOPE],
});
};

mcpOAuthMetadata.get(
ROOMOTE_MCP_PROTECTED_RESOURCE_METADATA_PATH,
protectedResourceMetadataHandler,
);
mcpOAuthMetadata.get(
LEGACY_ROOMOTE_MCP_PROTECTED_RESOURCE_METADATA_PATH,
protectedResourceMetadataHandler,
);
Loading
Loading