@markmnl/fmsg-mcp 0.1.4 → 0.2.0
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/CHANGELOG.md +49 -0
- package/README.md +78 -22
- package/ROADMAP.md +52 -0
- package/SECURITY.md +72 -0
- package/dist/auth.d.ts +14 -6
- package/dist/auth.js +115 -49
- package/dist/client/client.d.ts +34 -24
- package/dist/client/client.js +152 -105
- package/dist/client/errors.d.ts +19 -0
- package/dist/client/errors.js +51 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/stream.d.ts +12 -0
- package/dist/client/stream.js +83 -0
- package/dist/client/token-provider.d.ts +27 -0
- package/dist/client/token-provider.js +54 -0
- package/dist/client/types.d.ts +8 -4
- package/dist/client/url.d.ts +4 -0
- package/dist/client/url.js +35 -0
- package/dist/client/ws.d.ts +2 -1
- package/dist/client/ws.js +9 -3
- package/dist/config.d.ts +7 -3
- package/dist/config.js +15 -6
- package/dist/context.d.ts +6 -3
- package/dist/context.js +9 -2
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +18 -26
- package/dist/http.d.ts +4 -3
- package/dist/http.js +158 -23
- package/dist/index.js +27 -11
- package/dist/instructions.js +10 -5
- package/dist/oauth/config.d.ts +11 -0
- package/dist/oauth/config.js +46 -0
- package/dist/oauth/errors.d.ts +18 -0
- package/dist/oauth/errors.js +40 -0
- package/dist/oauth/issuer.d.ts +31 -0
- package/dist/oauth/issuer.js +185 -0
- package/dist/oauth/provider.d.ts +23 -0
- package/dist/oauth/provider.js +95 -0
- package/dist/oauth/scopes.d.ts +6 -0
- package/dist/oauth/scopes.js +31 -0
- package/dist/render.d.ts +6 -1
- package/dist/render.js +27 -11
- package/dist/resources.js +18 -9
- package/dist/server.js +2 -0
- package/dist/thread.js +15 -14
- package/dist/tools/common.js +8 -3
- package/dist/tools/identity.js +1 -1
- package/dist/tools/list.js +3 -3
- package/dist/tools/read.js +26 -43
- package/dist/tools/save.d.ts +2 -0
- package/dist/tools/save.js +84 -0
- package/dist/tools/send.js +9 -13
- package/dist/tools/wait.js +8 -6
- package/dist/wait.d.ts +1 -1
- package/dist/wait.js +161 -67
- package/docs/http-deployment.md +53 -0
- package/docs/oauth.md +163 -0
- package/docs/token-providers.md +94 -0
- package/package.json +8 -1
- package/server.json +7 -2
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# HTTP deployment behind TLS
|
|
2
|
+
|
|
3
|
+
This example runs Caddy and fmsg-mcp on the same machine. Replace `mcp.example.com` with your DNS
|
|
4
|
+
name pointing to that machine; Caddy needs access to ports 80/443 for automatic public TLS.
|
|
5
|
+
Keep port 8765 bound to loopback. The command below uses API keys; for OAuth add the
|
|
6
|
+
[OAuth configuration](oauth.md#operator-configuration).
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
FMSG_API_URL=https://api.example.com \
|
|
10
|
+
FMSG_MCP_ALLOWED_HOSTS=mcp.example.com \
|
|
11
|
+
FMSG_MCP_ALLOWED_ORIGINS=https://mcp.example.com,https://app.example.com \
|
|
12
|
+
npx -y @markmnl/fmsg-mcp --http 127.0.0.1:8765
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`FMSG_API_KEY` must be unset in HTTP mode. Include only browser origins you use. Behind TLS,
|
|
16
|
+
list the public HTTPS origin explicitly: the server sees the proxy's HTTP connection and does
|
|
17
|
+
not trust forwarded headers to establish the request origin.
|
|
18
|
+
|
|
19
|
+
Save this as `Caddyfile`:
|
|
20
|
+
|
|
21
|
+
```caddyfile
|
|
22
|
+
mcp.example.com {
|
|
23
|
+
@fmsg path /mcp /.well-known/oauth-protected-resource /.well-known/oauth-protected-resource/*
|
|
24
|
+
handle @fmsg {
|
|
25
|
+
reverse_proxy 127.0.0.1:8765 {
|
|
26
|
+
transport http {
|
|
27
|
+
response_header_timeout 240s
|
|
28
|
+
read_timeout 240s
|
|
29
|
+
write_timeout 60s
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
respond 404
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Validate with `caddy validate --config Caddyfile --adapter caddyfile`, then run Caddy using your
|
|
38
|
+
service manager. The `/healthz` liveness endpoint remains available locally at
|
|
39
|
+
`http://127.0.0.1:8765/healthz`. The public MCP URL is `https://mcp.example.com/mcp`.
|
|
40
|
+
|
|
41
|
+
Caddy preserves the Host, Authorization, Origin and MCP headers. It flushes SSE responses
|
|
42
|
+
immediately by default. Keep the default flush setting: `flush_interval -1` disables backend
|
|
43
|
+
cancellation on early disconnect. Do not enable automatic retries for sending requests.
|
|
44
|
+
See [Caddy's streaming and proxy documentation](https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#streaming).
|
|
45
|
+
|
|
46
|
+
For another proxy, preserve these headers and streaming behavior, propagate disconnects, and
|
|
47
|
+
allow response idle time beyond `FMSG_MCP_WAIT_MAX_SECONDS` with assembly headroom. Validate
|
|
48
|
+
allowed and denied Host/Origin requests, unauthenticated 401 responses, CORS preflight, a read,
|
|
49
|
+
and cancellation through the actual deployed proxy before advertising that deployment.
|
|
50
|
+
|
|
51
|
+
The metadata routes are public in OAuth mode and must reach the server for MCP authorization
|
|
52
|
+
discovery. In API-key mode they return 404. When OAuth is configured, its resource URL supplies
|
|
53
|
+
the public same-origin value, so explicitly listing that origin is optional.
|
package/docs/oauth.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# HTTP OAuth
|
|
2
|
+
|
|
3
|
+
OAuth is an optional HTTP authentication mode. API-key HTTP and stdio remain available with
|
|
4
|
+
`FMSG_MCP_AUTH_MODE=api-key` (the default). Each endpoint uses one mode; run separate instances
|
|
5
|
+
if you need both. There is no API-key fallback in OAuth mode.
|
|
6
|
+
|
|
7
|
+
A user adds the public MCP URL to a compatible host, signs in with the configured authorization
|
|
8
|
+
server, and consents to messaging scopes. The host handles authorization-code/PKCE and refresh;
|
|
9
|
+
fmsg-mcp validates its access token and exchanges it for a separate Web API token. Users do not
|
|
10
|
+
need to create an fmsg API key for this connection. The MCP server's exchange secret belongs to
|
|
11
|
+
the operator and is never given to users or AI hosts.
|
|
12
|
+
|
|
13
|
+
## Operator configuration
|
|
14
|
+
|
|
15
|
+
Provision an OAuth resource and a confidential exchange client at your authorization server.
|
|
16
|
+
Use the exact same resource URI in its resource registration, MCP configuration and host setup.
|
|
17
|
+
The Web API must support [delegated OAuth claims](https://github.com/markmnl/fmsg-webapi/blob/main/docs/oauth-claims.md),
|
|
18
|
+
with distinct OAuth and owner audiences. Configure the IdP's exchange target to issue that OAuth
|
|
19
|
+
audience and the consented address, with `fmsg:read` and/or `fmsg:write`.
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
export FMSG_API_URL=https://api.example.com
|
|
23
|
+
export FMSG_MCP_AUTH_MODE=oauth
|
|
24
|
+
export FMSG_MCP_OAUTH_RESOURCE_URL=https://mcp.example.com/mcp
|
|
25
|
+
export FMSG_MCP_OAUTH_ISSUER_URL=https://idp.example.com/oauth
|
|
26
|
+
export FMSG_MCP_OAUTH_CLIENT_ID=fmsg-mcp
|
|
27
|
+
export FMSG_MCP_OAUTH_EXCHANGE_AUDIENCE=fmsg-webapi
|
|
28
|
+
export FMSG_MCP_ALLOWED_HOSTS=mcp.example.com
|
|
29
|
+
# Supply FMSG_MCP_OAUTH_CLIENT_SECRET through your service's secret manager.
|
|
30
|
+
# Leave FMSG_API_KEY unset.
|
|
31
|
+
npx -y @markmnl/fmsg-mcp --http 127.0.0.1:8765
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
| Setting | Required in OAuth mode | Meaning |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| `FMSG_MCP_OAUTH_RESOURCE_URL` | Yes | Exact public MCP URL, including `/mcp`; also the incoming JWT audience |
|
|
37
|
+
| `FMSG_MCP_OAUTH_ISSUER_URL` | Yes | Exact authorization-server issuer, including any path |
|
|
38
|
+
| `FMSG_MCP_OAUTH_CLIENT_ID` | Yes | This MCP server's confidential token-exchange client ID |
|
|
39
|
+
| `FMSG_MCP_OAUTH_CLIENT_SECRET` | Yes | Its exchange secret; sent only in HTTP Basic authentication |
|
|
40
|
+
| `FMSG_MCP_OAUTH_EXCHANGE_AUDIENCE` | Yes | Actual Web API OAuth audience; must differ from the MCP resource URI |
|
|
41
|
+
| `FMSG_MCP_OAUTH_ADDRESS_CLAIM` | No; `sub` | Incoming JWT claim containing the consented full `@user@domain` address |
|
|
42
|
+
| `FMSG_API_URL` | Yes | Fixed deployed Web API base URL |
|
|
43
|
+
|
|
44
|
+
Use the actual audience value for `EXCHANGE_AUDIENCE`, even if the IdP also supports target
|
|
45
|
+
aliases: fmsg-mcp checks the returned JWT audience against this value. In the example the Web API
|
|
46
|
+
and IdP target must both use `fmsg-webapi` as their OAuth audience. The outgoing token's `sub`
|
|
47
|
+
must equal the incoming consented address; its issuer/signature are validated by the Web API.
|
|
48
|
+
If your IdP stores a hash of the exchange secret, provision its SHA-256 there and give the original
|
|
49
|
+
secret to this server. Never put the secret in source control or client configuration.
|
|
50
|
+
|
|
51
|
+
OAuth URLs require HTTPS, with HTTP permitted only on loopback for local testing. Discovery,
|
|
52
|
+
JWKS and exchange requests refuse redirects and have a five-second/64-KiB response budget.
|
|
53
|
+
Configuration is vendor neutral, but authorization servers must implement the token profile below;
|
|
54
|
+
an arbitrary OAuth provider without token exchange is not sufficient.
|
|
55
|
+
|
|
56
|
+
Use the [TLS deployment recipe](http-deployment.md), including its metadata routes. Browser hosts
|
|
57
|
+
on other origins need `FMSG_MCP_ALLOWED_ORIGINS`. The configured resource origin is accepted as
|
|
58
|
+
same-origin behind a TLS proxy; forwarded headers never select an issuer, resource or token endpoint.
|
|
59
|
+
|
|
60
|
+
## Discovery and client onboarding
|
|
61
|
+
|
|
62
|
+
Public [RFC 9728](https://www.rfc-editor.org/rfc/rfc9728.html) metadata is served at
|
|
63
|
+
`/.well-known/oauth-protected-resource` and the resource-specific path
|
|
64
|
+
`/.well-known/oauth-protected-resource/mcp`. Both advertise the exact configured resource,
|
|
65
|
+
authorization server, supported scopes and header bearer authentication. A resource served under
|
|
66
|
+
another public path requires the corresponding metadata path to reach this process too.
|
|
67
|
+
Unauthenticated or invalid-token requests receive `401` with a `WWW-Authenticate: Bearer`
|
|
68
|
+
challenge containing `resource_metadata`.
|
|
69
|
+
|
|
70
|
+
Authorization-server metadata uses [RFC 8414](https://www.rfc-editor.org/rfc/rfc8414.html):
|
|
71
|
+
issuer `https://idp.example.com/oauth` is discovered at
|
|
72
|
+
`https://idp.example.com/.well-known/oauth-authorization-server/oauth`. A 404 permits the
|
|
73
|
+
OpenID-style discovery fallback below the issuer. The discovered issuer must match exactly.
|
|
74
|
+
Only its `jwks_uri` is used; the server does not guess `/.well-known/jwks.json` or trust JWT
|
|
75
|
+
`jku`/`x5u` headers. Discovery and keys cache for five minutes. An unknown signing key can trigger
|
|
76
|
+
a refresh after a five-second fetch cooldown; publish new keys before using them.
|
|
77
|
+
|
|
78
|
+
Client registration belongs to the authorization server. If it offers no dynamic registration,
|
|
79
|
+
use pre-registered clients or Client ID Metadata Documents where supported by both server and
|
|
80
|
+
host. Check the intended host's registration support before advertising compatibility. This
|
|
81
|
+
implementation does not add a registration proxy, login UI or consent UI.
|
|
82
|
+
|
|
83
|
+
## Token validation and scopes
|
|
84
|
+
|
|
85
|
+
Incoming access tokens must be signed EdDSA JWTs with `typ: at+jwt`, a nonempty `kid` in the
|
|
86
|
+
discovered key set, exact `iss`, and exactly one audience equal to the resource URI. Signature,
|
|
87
|
+
`exp` and any `nbf` are checked on every request. `sub` is required, the configured address claim
|
|
88
|
+
must contain a full fmsg address, and `scope` is a space-delimited string. Unrecognized scopes
|
|
89
|
+
grant no messaging capability. Tokens for another audience, including Web API/owner tokens,
|
|
90
|
+
are refused.
|
|
91
|
+
|
|
92
|
+
| Operations | Required scope |
|
|
93
|
+
|---|---|
|
|
94
|
+
| Identity/address lookup, inbox/sent, message/thread, delivery status, attachment download, wait, resource reads | `fmsg:read` |
|
|
95
|
+
| Send a new message, add recipients, react, mark read | `fmsg:write` |
|
|
96
|
+
| Reply (reads the parent before sending) | `fmsg:read fmsg:write` |
|
|
97
|
+
| Protocol initialization, tool/resource/prompt discovery and prompt templates | Valid incoming token; no messaging scope needed |
|
|
98
|
+
|
|
99
|
+
Missing scope returns `403` with `error="insufficient_scope"` and the required `scope` in the
|
|
100
|
+
bearer challenge. The SDK then validates tool arguments and dispatches the request. Scopes are
|
|
101
|
+
checked against the actual request body, including resource reads; JSON batches are refused.
|
|
102
|
+
The Web API still decides message visibility, recipients, account grants, quotas and acceptance.
|
|
103
|
+
No duplicate messaging ACLs or per-message approvals are introduced.
|
|
104
|
+
|
|
105
|
+
## Exchange, renewal and revocation
|
|
106
|
+
|
|
107
|
+
For protected operations, fmsg-mcp calls the discovered token endpoint with an
|
|
108
|
+
[RFC 8693](https://www.rfc-editor.org/rfc/rfc8693.html) form: token-exchange `grant_type`, incoming
|
|
109
|
+
`subject_token`, access-token `subject_token_type`, configured `audience`, and the granted
|
|
110
|
+
messaging `scope`. HTTP Basic carries the server client ID and secret. The incoming token is
|
|
111
|
+
never sent to the Web API, and `X-FMSG-Act-As` is never set.
|
|
112
|
+
|
|
113
|
+
The response must contain a separate JWT `access_token`, Bearer `token_type`, access-token
|
|
114
|
+
`issued_token_type`, positive `expires_in`, matching `scope`, and no refresh token. Its audience,
|
|
115
|
+
address, expiry and scopes are checked before use; the trusted token endpoint issues it, and the
|
|
116
|
+
Web API verifies its signature and issuer. Delegated tokens must not reach owner-only routes
|
|
117
|
+
such as sub-account, API-key or push administration, even outside the MCP tool surface.
|
|
118
|
+
|
|
119
|
+
Each incoming token has its own client and cache, even when two tokens name the same user.
|
|
120
|
+
The cache lifetime is the earliest of `expires_in`, exchanged JWT expiry, incoming JWT expiry
|
|
121
|
+
and five minutes from the exchange request. Renewal normally starts halfway through that lifetime.
|
|
122
|
+
`FMSG_MCP_KEY_CACHE_MAX` bounds retained client entries; idle OAuth entries are evicted after five
|
|
123
|
+
minutes. `FMSG_MCP_KEY_CACHE_TTL_SECONDS` applies only to API-key mode and cannot extend OAuth
|
|
124
|
+
credentials. Active requests retain their own leases through cache eviction. No token is persisted.
|
|
125
|
+
|
|
126
|
+
Web API `401` retries once after re-exchange; `403` never retries. An expiry timer closes an OAuth
|
|
127
|
+
WebSocket by its cached credential deadline, even if the Web API leaves it open. Waits reconnect,
|
|
128
|
+
catch up, and retain their original cursor, accumulated batch and timeout. Network failures use
|
|
129
|
+
bounded reconnect backoff with polling; cancellation closes sockets and stops exchange work.
|
|
130
|
+
This does not resolve the separate large-backlog/pending-thread cursor work in [ROADMAP.md](../ROADMAP.md).
|
|
131
|
+
|
|
132
|
+
- `invalid_grant` from exchange means `401`: refresh or reconnect the client connection.
|
|
133
|
+
- `invalid_client` / `invalid_target` means `500` plus a sanitized operator-action log. Monitor this
|
|
134
|
+
log as an alert; correct the exchange configuration rather than asking users to sign in again.
|
|
135
|
+
- Unavailable discovery/JWKS/exchange means `503`; there is no fallback credential.
|
|
136
|
+
- Web API `403` with `insufficient_scope` is returned as a scope challenge. It may indicate either
|
|
137
|
+
missing scope or a route permanently closed to delegated tokens; additional consent cannot open
|
|
138
|
+
owner-only routes.
|
|
139
|
+
|
|
140
|
+
Authentication is checked before protected responses start. A later authentication failure also
|
|
141
|
+
becomes an HTTP challenge if headers have not been sent. Once a long wait has streamed progress,
|
|
142
|
+
HTTP cannot change its status: it finishes with an MCP authentication error and the next request
|
|
143
|
+
receives the appropriate challenge. Hosts should reconnect/refresh after that error, not repeat sends.
|
|
144
|
+
|
|
145
|
+
Offline validation cannot instantly detect revocation. With ten-minute incoming and five-minute
|
|
146
|
+
exchanged tokens, discovery operations may accept a revoked incoming token for up to ten minutes;
|
|
147
|
+
new Web API requests stop within five minutes once exchange starts refusing the grant. Longer
|
|
148
|
+
IdP lifetimes extend offline acceptance at the corresponding service. The MCP cache/socket cap
|
|
149
|
+
stays five minutes, but a copied upstream token remains usable directly until its actual expiry.
|
|
150
|
+
Configure upstream lifetimes to meet your intended revocation guarantee.
|
|
151
|
+
|
|
152
|
+
## Validation and rollout
|
|
153
|
+
|
|
154
|
+
`test/oauth.test.ts` uses a local authorization server with real Ed25519 signatures and separate
|
|
155
|
+
OAuth/Web API keys. It exercises discovery, invalid claims, scopes, exchange, caller isolation,
|
|
156
|
+
revocation, token expiry and waiting across reconnects. The fake Web API accepts registered token
|
|
157
|
+
fixtures; it is not a substitute for the Web API's JWT authorization tests.
|
|
158
|
+
|
|
159
|
+
Before enabling a hosted deployment, verify the deployed IdP and Web API audience configuration,
|
|
160
|
+
then exercise sign-in/consent, `whoami`, send/read/reply, refresh, revoked grants, scope denial and
|
|
161
|
+
wait cancellation through the real TLS proxy in each advertised MCP host. No live hosted-client
|
|
162
|
+
or deployed IdP compatibility is claimed by the local tests. API-key integration can keep running
|
|
163
|
+
while these services are prepared.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Web API token providers
|
|
2
|
+
|
|
3
|
+
`FmsgClient` accepts either the existing `fmsgk_…` API-key string or a `TokenProvider`.
|
|
4
|
+
This is a client-library extension point. The MCP executable uses it for API keys and
|
|
5
|
+
optional [HTTP OAuth](oauth.md), including discovery, JWT validation and RFC 8693 exchange.
|
|
6
|
+
|
|
7
|
+
Import `TokenProvider`, `TokenProviderRequest` and `AccessToken` from
|
|
8
|
+
`@markmnl/fmsg-mcp/client` (also exported from the package root):
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
interface TokenProvider {
|
|
12
|
+
getToken(request: {
|
|
13
|
+
apiUrl: string;
|
|
14
|
+
signal: AbortSignal;
|
|
15
|
+
forceRefresh: boolean;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
accessToken: string;
|
|
18
|
+
address: string;
|
|
19
|
+
expiresAtMs: number;
|
|
20
|
+
}>;
|
|
21
|
+
close?(): void;
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Supply an implementation as `new FmsgClient(apiUrl, tokenProvider, options)`.
|
|
26
|
+
One provider and client belong to one caller, authorization grant and Web API URL.
|
|
27
|
+
Sharing a provider between clients risks mixing grants or closing another client's credentials.
|
|
28
|
+
|
|
29
|
+
## Provider responsibilities
|
|
30
|
+
|
|
31
|
+
- Obtain a fresh **Web API** bearer access token whenever called. `apiUrl` is the
|
|
32
|
+
normalized, fixed upstream URL; never derive credential destinations from model input.
|
|
33
|
+
`forceRefresh: true` means the previous token was rejected with 401 or renewal was
|
|
34
|
+
explicitly requested. It must bypass any provider cache of that rejected token.
|
|
35
|
+
- Return the authenticated fmsg address that the token authorizes, preserving user-name
|
|
36
|
+
case, and a finite future expiry in milliseconds since the Unix epoch. Use trusted
|
|
37
|
+
authorization/exchange metadata; do not invent an expiry or infer identity from an
|
|
38
|
+
unverified incoming token. The generic client does not decode provider tokens.
|
|
39
|
+
- Honour `signal` for all network work. It aborts when renewal times out, the client
|
|
40
|
+
closes, or all callers waiting for that renewal cancel. Reject on failed/revoked
|
|
41
|
+
authorization; never fall back to an owner token, API key or another grant.
|
|
42
|
+
- Keep credentials out of errors and logs. `close()` synchronously releases retained
|
|
43
|
+
credentials/resources; it is called once when the owning client closes. Closing a
|
|
44
|
+
client is local cleanup, not remote OAuth-grant revocation.
|
|
45
|
+
|
|
46
|
+
## Client responsibilities
|
|
47
|
+
|
|
48
|
+
The client caches immutable token snapshots and shares concurrent renewal. It renews
|
|
49
|
+
five minutes before expiry by default, capped at half the remaining lifetime when the
|
|
50
|
+
token is acquired, so a one-minute token is usable without constant re-exchange.
|
|
51
|
+
`refreshMarginMs: 0` disables early renewal, but never permits an expired cached token.
|
|
52
|
+
Each acquisition has the client's `timeoutMs` budget (60 seconds by default).
|
|
53
|
+
|
|
54
|
+
The first successful acquisition pins the address. A renewal for another address is
|
|
55
|
+
rejected before any request uses that token; changing identities requires a new client.
|
|
56
|
+
This is caller binding, not an additional messaging permission system. The Web API
|
|
57
|
+
still validates the actual credential, identity, scopes, visibility and host limits.
|
|
58
|
+
|
|
59
|
+
Protected HTTP requests retry once on 401 after renewal. Concurrent or late 401s for
|
|
60
|
+
the same old token reuse an already renewed token; 403 never triggers renewal.
|
|
61
|
+
Failed renewal discards the cache. Provider output must be a bearer token with a valid
|
|
62
|
+
address and expiry; an API key passed back as an access token is rejected.
|
|
63
|
+
|
|
64
|
+
`getToken(force?, signal?)` and `address(signal?)` support cancellation, as do existing
|
|
65
|
+
request methods that accept a signal. Cancelling one waiter leaves renewal available
|
|
66
|
+
to others; cancelling the last aborts acquisition. Late provider completion cannot
|
|
67
|
+
replace a later token. `close()` aborts outstanding token acquisition and HTTP work.
|
|
68
|
+
|
|
69
|
+
`openFmsgWebSocket(client, signal?)` obtains its bearer from the same provider/cache.
|
|
70
|
+
The optional signal cancels token acquisition before opening the socket. The caller
|
|
71
|
+
owns the returned WebSocket and must handle its events and close it; long-lived
|
|
72
|
+
connections do not gain automatic token renewal or revocation handling from this helper.
|
|
73
|
+
`wait_for_message` owns its socket and passes cancellation into acquisition. With
|
|
74
|
+
`reconnectOnTokenExpiry: true`, it closes and reopens sockets by the token metadata expiry,
|
|
75
|
+
retaining the original wait deadline and cursor; OAuth mode enables this option.
|
|
76
|
+
|
|
77
|
+
## OAuth adapter contract
|
|
78
|
+
|
|
79
|
+
Validate the incoming MCP access token for the configured issuer and MCP audience,
|
|
80
|
+
then use authenticated [RFC 8693 token exchange](https://www.rfc-editor.org/rfc/rfc8693.html)
|
|
81
|
+
to obtain a separate upstream token. [MCP forbids passing the incoming token through
|
|
82
|
+
to the Web API](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization/security-considerations).
|
|
83
|
+
Keep issuer, JWKS/discovery URLs, audiences, address-claim mapping and client credentials
|
|
84
|
+
configurable; no particular identity provider is required by this interface.
|
|
85
|
+
|
|
86
|
+
The IdP and Web API must agree on scopes and consented-identity binding before hosted
|
|
87
|
+
OAuth is enabled. Exchanged messaging tokens must not acquire owner key-management
|
|
88
|
+
rights or broaden identity via `X-FMSG-Act-As`. The Web API enforces those restrictions;
|
|
89
|
+
the tool list is not an authorization boundary. Browser consent and refresh/revocation endpoints belong to the authorization service and host. Offline JWT validation alone does not
|
|
90
|
+
provide immediate revocation of already issued upstream tokens.
|
|
91
|
+
|
|
92
|
+
Tests in `test/token-provider.test.ts` use registered opaque token fixtures to exercise
|
|
93
|
+
renewal, cancellation, caller isolation, and HTTP/WebSocket credential delivery. They
|
|
94
|
+
do not establish OAuth conformance, JWT verification, or compatibility with a real IdP.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markmnl/fmsg-mcp",
|
|
3
3
|
"mcpName": "io.github.markmnl/fmsg-mcp",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "MCP server for fmsg: send and receive federated messages from any AI agent via a deployed fmsg Web API",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,6 +42,12 @@
|
|
|
42
42
|
"dist/**/*.js",
|
|
43
43
|
"dist/**/*.d.ts",
|
|
44
44
|
"README.md",
|
|
45
|
+
"SECURITY.md",
|
|
46
|
+
"CHANGELOG.md",
|
|
47
|
+
"ROADMAP.md",
|
|
48
|
+
"docs/http-deployment.md",
|
|
49
|
+
"docs/token-providers.md",
|
|
50
|
+
"docs/oauth.md",
|
|
45
51
|
"LICENSE",
|
|
46
52
|
"server.json"
|
|
47
53
|
],
|
|
@@ -61,6 +67,7 @@
|
|
|
61
67
|
},
|
|
62
68
|
"dependencies": {
|
|
63
69
|
"@modelcontextprotocol/server": "^2.0.0",
|
|
70
|
+
"jose": "^6.2.12",
|
|
64
71
|
"ws": "^8.21.3",
|
|
65
72
|
"zod": "^4.5.4"
|
|
66
73
|
},
|
package/server.json
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
"url": "https://github.com/markmnl/fmsg-mcp",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.2.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
14
14
|
"identifier": "@markmnl/fmsg-mcp",
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.2.0",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
},
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
"name": "FMSG_DEFAULT_DOMAIN",
|
|
33
33
|
"description": "Optional: lets short names resolve to @name@<domain>",
|
|
34
34
|
"isRequired": false
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "FMSG_MCP_DOWNLOAD_DIR",
|
|
38
|
+
"description": "Optional local folder enabling streamed attachment saves over stdio",
|
|
39
|
+
"isRequired": false
|
|
35
40
|
}
|
|
36
41
|
]
|
|
37
42
|
}
|