Skip to main content
Glama
index.ts2.37 kB
import { Hono } from "hono"; import { DurableMCP } from "workers-mcp"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import OAuthProvider, { type OAuthHelpers } from "@cloudflare/workers-oauth-provider"; import { z } from "zod"; import type { UserProps } from "./types"; import { authorize, callback, confirmConsent, tokenExchangeCallback } from "./auth"; import { getEmbedding, searchVectorDB } from "./utils"; export class AuthenticatedMCP extends DurableMCP<UserProps, Env> { server = new McpServer({ name: "Auth0 OIDC Proxy Demo", version: "1.0.0", }); async init() { // Useful for debugging. This will show the current user's claims and the Auth0 tokens. // Get the current user's billing settings. // Note that read:billing is not being requested by the MCP server, meaning that this request will fail. // This is to show it's possible to implement scenarios where the MCP server can only call the APIs which the user has consented to. this.server.tool( "sssojetDocs", "Search through documentation using vector similarity", { query: z.string().describe("The search query to find relevant documentation"), limit: z.number().optional().describe("Maximum number of results to return") }, async ({ query, limit = 5 }) => { try { const queryEmbedding = await getEmbedding(query); const results = await searchVectorDB(queryEmbedding, "ssojet-documents", limit); return { content: [ { type: "text", text: JSON.stringify(results, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text", text: `Error processing query: ${error.message}` } ] }; } }, ); } } // Initialize the Hono app with the routes for the OAuth Provider. const app = new Hono<{ Bindings: Env & { OAUTH_PROVIDER: OAuthHelpers } }>(); app.get("/authorize", authorize); app.post("/authorize/consent", confirmConsent); app.get("/callback", callback); export default new OAuthProvider({ apiRoute: "/sse", // TODO: fix these types // @ts-ignore apiHandler: AuthenticatedMCP.mount("/sse"), // TODO: fix these types // @ts-ignore defaultHandler: app, authorizeEndpoint: "/authorize", tokenEndpoint: "/token", clientRegistrationEndpoint: "/register", tokenExchangeCallback, });

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pratham-svg/MCP-OAuth'

If you have feedback or need assistance with the MCP directory API, please join our Discord server