findymail-mcp 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/http.js +44 -16
package/package.json
CHANGED
package/src/http.js
CHANGED
|
@@ -33,16 +33,51 @@ app.use((req, res, next) => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// =============================================================================
|
|
36
|
-
//
|
|
36
|
+
// OAuth 2.0 endpoints (required for HTTP transport)
|
|
37
37
|
// =============================================================================
|
|
38
38
|
|
|
39
|
-
app.get("/.well-known/oauth-
|
|
40
|
-
log("
|
|
39
|
+
app.get("/.well-known/oauth-authorization-server", (req, res) => {
|
|
40
|
+
log("OAuth metadata requested");
|
|
41
41
|
res.json({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
issuer: BASE_URL,
|
|
43
|
+
authorization_endpoint: `${BASE_URL}/authorize`,
|
|
44
|
+
token_endpoint: `${BASE_URL}/token`,
|
|
45
|
+
registration_endpoint: `${BASE_URL}/register`,
|
|
46
|
+
response_types_supported: ["code"],
|
|
47
|
+
grant_types_supported: ["authorization_code", "refresh_token"],
|
|
48
|
+
code_challenge_methods_supported: ["S256"],
|
|
49
|
+
token_endpoint_auth_methods_supported: ["none"],
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
app.post("/register", (req, res) => {
|
|
54
|
+
log("Client registration");
|
|
55
|
+
const clientId = `client_${Date.now()}`;
|
|
56
|
+
res.status(201).json({
|
|
57
|
+
client_id: clientId,
|
|
58
|
+
client_id_issued_at: Math.floor(Date.now() / 1000),
|
|
59
|
+
redirect_uris: req.body?.redirect_uris || [],
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
app.get("/authorize", (req, res) => {
|
|
64
|
+
log(`Authorization requested for client: ${req.query.client_id}`);
|
|
65
|
+
const code = `code_${Date.now()}`;
|
|
66
|
+
const redirectUri = new URL(req.query.redirect_uri);
|
|
67
|
+
redirectUri.searchParams.set("code", code);
|
|
68
|
+
if (req.query.state) {
|
|
69
|
+
redirectUri.searchParams.set("state", req.query.state);
|
|
70
|
+
}
|
|
71
|
+
log("Auto-approving authorization");
|
|
72
|
+
res.redirect(redirectUri.toString());
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
app.post("/token", (req, res) => {
|
|
76
|
+
log("Token exchange");
|
|
77
|
+
res.json({
|
|
78
|
+
access_token: `access_${Date.now()}`,
|
|
79
|
+
token_type: "Bearer",
|
|
80
|
+
expires_in: 3600,
|
|
46
81
|
});
|
|
47
82
|
});
|
|
48
83
|
|
|
@@ -66,20 +101,13 @@ function createMcpServer() {
|
|
|
66
101
|
// =============================================================================
|
|
67
102
|
|
|
68
103
|
app.use("/mcp", (req, res, next) => {
|
|
69
|
-
const wwwAuth = `Bearer resource_metadata="${BASE_URL}/.well-known/oauth-protected-resource"`;
|
|
70
104
|
const authHeader = req.headers.authorization;
|
|
71
105
|
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
72
|
-
return res
|
|
73
|
-
.status(401)
|
|
74
|
-
.set("WWW-Authenticate", wwwAuth)
|
|
75
|
-
.json({ error: "Authorization header with Bearer token is required" });
|
|
106
|
+
return res.status(401).json({ error: "Authorization header with Bearer token is required" });
|
|
76
107
|
}
|
|
77
108
|
const token = authHeader.slice(7).trim();
|
|
78
109
|
if (!token) {
|
|
79
|
-
return res
|
|
80
|
-
.status(401)
|
|
81
|
-
.set("WWW-Authenticate", wwwAuth)
|
|
82
|
-
.json({ error: "Bearer token is empty" });
|
|
110
|
+
return res.status(401).json({ error: "Bearer token is empty" });
|
|
83
111
|
}
|
|
84
112
|
req.auth = { token, clientId: "", scopes: [] };
|
|
85
113
|
next();
|