Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(mcp): add OAuth 2.0 well-known endpoints for authorization server

Andreja271249a12c1
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index 042581d74..12d7659d9 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -425,6 +425,10 @@ export function createApp() {
api.route("/", mcpRoutes);
api.use("*", async (c, next) => {
+ const path = c.req.path;
+ if (path.startsWith("/api/mcp") || path.startsWith("/api/.well-known/")) {
+ return next();
+ }
try {
await authenticateApiRequest(c);
} catch (error) {
diff --git a/apps/api/src/mcp/index.ts b/apps/api/src/mcp/index.ts
index 808f07594..a4cacb182 100644
--- a/apps/api/src/mcp/index.ts
+++ b/apps/api/src/mcp/index.ts
@@ -242,9 +242,31 @@ mcp.post("/mcp/token", async (c) => {
});
});
+mcp.get("/.well-known/oauth-protected-resource/api/mcp", (c) =>
+ c.json({
+ resource: `${apiUrl}/api/mcp`,
+ authorization_servers: [`${apiUrl}/api`],
+ }),
+);
+
+mcp.get("/.well-known/oauth-authorization-server/api", (c) =>
+ c.json({
+ issuer: `${apiUrl}/api`,
+ authorization_endpoint: `${apiUrl}/api/mcp/authorize`,
+ token_endpoint: `${apiUrl}/api/mcp/token`,
+ registration_endpoint: `${apiUrl}/api/mcp/register`,
+ response_types_supported: ["code"],
+ grant_types_supported: ["authorization_code"],
+ code_challenge_methods_supported: ["S256"],
+ token_endpoint_auth_methods_supported: ["none"],
+ }),
+);
+
mcp.all("/mcp", async (c) => {
const authResult = await validateBearerToken(c.req.raw);
if (!authResult) {
+ const prmUrl = `${apiUrl}/api/.well-known/oauth-protected-resource/api/mcp`;
+ c.header("WWW-Authenticate", `Bearer resource_metadata="${prmUrl}"`);
return c.json(
{
error: "invalid_token",