mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-09 20:27:44 +00:00
feat: MCP plugin (#2666)
* chore: wip * wip * feat: mcp plugin * wip * chore: fix lock file * clean up * schema * docs * chore: lint * chore: release v1.2.9-beta.1 * blog * chore: lint
This commit is contained in:
38
examples/nextjs-mcp/app/api/[transport]/route.ts
Normal file
38
examples/nextjs-mcp/app/api/[transport]/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { auth } from "@/lib/auth";
|
||||
import { createMcpHandler } from "@vercel/mcp-adapter";
|
||||
import { withMcpAuth } from "better-auth/plugins";
|
||||
import { z } from "zod";
|
||||
|
||||
const handler = withMcpAuth(auth, (req, sesssion) => {
|
||||
return createMcpHandler(
|
||||
(server) => {
|
||||
server.tool(
|
||||
"echo",
|
||||
"Echo a message",
|
||||
{ message: z.string() },
|
||||
async ({ message }) => {
|
||||
return {
|
||||
content: [{ type: "text", text: `Tool echo: ${message}` }],
|
||||
};
|
||||
},
|
||||
);
|
||||
},
|
||||
{
|
||||
capabilities: {
|
||||
tools: {
|
||||
echo: {
|
||||
description: "Echo a message",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
redisUrl: process.env.REDIS_URL,
|
||||
basePath: "/api",
|
||||
verboseLogs: true,
|
||||
maxDuration: 60,
|
||||
},
|
||||
)(req);
|
||||
});
|
||||
|
||||
export { handler as GET, handler as POST, handler as DELETE };
|
||||
4
examples/nextjs-mcp/app/api/auth/[...all]/route.ts
Normal file
4
examples/nextjs-mcp/app/api/auth/[...all]/route.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { auth } from "@/lib/auth";
|
||||
import { toNextJsHandler } from "better-auth/next-js";
|
||||
|
||||
export const { GET, POST } = toNextJsHandler(auth);
|
||||
Reference in New Issue
Block a user