import OAuthProvider from "@cloudflare/workers-oauth-provider";
import { McpAgent } from "agents/mcp";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { MyAuthHandler} from "./google-handler"
import type { Props } from "./props";
export class MyMCP extends McpAgent<Env, unknown, Props> {
server = new McpServer({
name: "Tracksuit MCP Demo",
version: "1.0.0",
});
async init() {
// Brand awareness tool
this.server.tool(
"brand_awareness",
{ brand_name: z.string() },
async ({ brand_name }) => {
const awareness =
brand_name.toLowerCase().trim() === "tracksuit" ? 100 : 0;
return {
content: [
{
type: "text",
text: `Brand awareness for ${brand_name}: ${awareness}%`,
},
],
};
},
);
}
}
export default new OAuthProvider({
apiRoute: "/mcp",
apiHandler: MyMCP.mount("/mcp") as any, // Use 'any' for maximum flexibility
defaultHandler: MyAuthHandler as any,
authorizeEndpoint: "/authorize",
tokenEndpoint: "/token",
clientRegistrationEndpoint: "/register",
});