Skip to content

Commit 19d3637

Browse files
Add tk.* guard, HttpPipeline DI, and hosted-endpoint docs for token elicitation
- Reject token creation up front when the server's access token is a temporary tk.* token (used by the hosted MCP endpoint), instead of letting the Mapbox API round-trip fail. The elicitation dialog now omits "create"/"auto-create" in that case and only offers "provide an existing token". - Move token-listing/creation off raw fetch() onto the shared HttpPipeline (constructor-injected httpRequest), consistent with other Mapbox API tools. - Document the hosted-endpoint limitation in README and CHANGELOG.
1 parent 14e54b3 commit 19d3637

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
## Unreleased
22

3+
### New Features
4+
5+
- **Secure token elicitation for `preview_style_tool` / `style_comparison_tool`** (#57): `accessToken` is now optional on both tools. When omitted, the tool uses MCP elicitation to ask for a public token instead — either pasting an existing `pk.*` token, creating a new one with optional URL restrictions, or auto-creating a minimally-scoped one (`styles:read`, `styles:tiles`, `fonts:read`). This keeps your server's `sk.*`/`pk.*` access token out of chat history and preview URLs. Falls back to requiring `accessToken` directly on clients without elicitation support (Claude Desktop, Claude Code). A chosen/created token is cached in memory per account for the session; pass `useCustomToken: true` to force re-selection.
6+
- On servers authenticated with a temporary `tk.*` token — notably the hosted MCP endpoint — Mapbox's Tokens API cannot create new tokens, so the "create a new token" and "auto-create" options are automatically omitted from the elicitation dialog rather than being offered and failing.
7+
8+
### Changed
9+
10+
- **`preview_style_tool` / `style_comparison_tool`**: token-listing and token-creation HTTP calls now go through the shared `HttpPipeline` (constructor-injected `httpRequest`) instead of a bare `fetch`, consistent with the rest of the API-calling tools.
11+
312
## 0.8.2 - 2026-07-30
413

514
### Fixed

‎README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Get started by integrating with your preferred AI development environment:
6969
- **Claude Desktop**: ⚠️ Not yet supported (Claude will fall back to creating tokens via chat)
7070
- **Claude Code**: ⚠️ Not yet supported (provide `accessToken` parameter directly)
7171

72+
**Note on the hosted MCP endpoint**: even on a client with full elicitation support, the [hosted endpoint](#hosted-mcp-endpoint) only offers **"I have a token to provide"** — see below for why.
73+
7274
### DXT Package Distribution
7375

7476
This MCP server can be packaged as a DXT (Desktop Extension) file for easy distribution and installation. DXT is a standardized format for distributing local MCP servers, similar to browser extensions.
@@ -105,6 +107,13 @@ For quick access, you can use our hosted MCP endpoint:
105107

106108
For detailed setup instructions for different clients and API usage, see the [Hosted MCP Server Guide](https://github.com/mapbox/mcp-server/blob/main/docs/hosted-mcp-guide.md). Note: This guide references the standard MCP endpoint - you'll need to update the endpoint URL to use the devkit endpoint above.
107109

110+
**Token creation is unavailable on the hosted endpoint**: the hosted server authenticates each request with a short-lived, per-session token (`tk.*`), not your own Mapbox account token. Mapbox's Tokens API never grants `tokens:write` to a `tk.*` token, so it cannot be used to create new tokens. As a result, on the hosted endpoint:
111+
112+
- `preview_style_tool` / `style_comparison_tool`'s elicitation dialog only offers **"I have a token to provide"** — the "create a new token" and "auto-create" options are hidden automatically, rather than being offered and then failing.
113+
- `create_token_tool` will fail with a permissions error if called directly.
114+
115+
Paste an existing public token (`pk.*`, with `styles:read` scope) when prompted, or create one ahead of time from your [Mapbox Account page](https://account.mapbox.com/). Running this server **locally** with your own `pk.*`/`sk.*` access token (which can carry `tokens:write`) restores all three elicitation options, including create and auto-create.
116+
108117
### Getting Your Mapbox Access Token
109118

110119
**A Mapbox access token is required to use this MCP server.**
@@ -194,6 +203,7 @@ Complete set of tools for managing Mapbox styles via the Styles API:
194203
3. **Auto-create a basic token** - Let the tool create a simple preview token for you
195204
- **Goose**: ⚠️ Known bug - Form displays after timeout ([goose#6471](https://github.com/block/goose/issues/6471))
196205
- **Claude Desktop, Claude Code**: ⚠️ Not yet supported - Provide `accessToken` parameter directly, or Claude will intelligently offer to create a token for you using `create_token_tool`
206+
- **Hosted MCP endpoint**: ⚠️ Only "provide an existing token" is offered, regardless of client — see [Token creation is unavailable on the hosted endpoint](#hosted-mcp-endpoint)
197207
- **Alternative**: Provide `accessToken` parameter directly for backward compatibility with any client
198208
- **Session Storage**: Your token choice is cached for the session, so you only need to provide it once (when elicitation is supported)
199209
- **Best Practice**: Use URL-restricted tokens to further limit token usage to specific domains. While public tokens in URLs are read-only, URL restrictions add an extra layer of security by ensuring tokens only work on your specified domains
@@ -216,6 +226,7 @@ Complete set of tools for managing Mapbox styles via the Styles API:
216226
3. **Auto-create a basic token** - Let the tool create a simple preview token for you
217227
- **Goose**: ⚠️ Known bug - Form displays after timeout ([goose#6471](https://github.com/block/goose/issues/6471))
218228
- **Claude Desktop, Claude Code**: ⚠️ Not yet supported - Provide `accessToken` parameter directly, or Claude will intelligently offer to create a token for you using `create_token_tool`
229+
- **Hosted MCP endpoint**: ⚠️ Only "provide an existing token" is offered, regardless of client — see [Token creation is unavailable on the hosted endpoint](#hosted-mcp-endpoint)
219230
- **Alternative**: Provide `accessToken` parameter directly for backward compatibility with any client
220231
- **Session Storage**: Your token choice is cached for the session, so you only need to provide it once (when elicitation is supported)
221232
- **Best Practice**: Use URL-restricted tokens to further limit token usage to specific domains. While public tokens in URLs are read-only, URL restrictions add an extra layer of security by ensuring tokens only work on your specified domains

‎src/utils/tokenElicitation.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ export async function elicitPreviewToken(
7575
.join('\n')
7676
: 'No existing public tokens found.';
7777

78-
const choices = canCreateTokens
79-
? (['provide', 'create', 'auto'] as const)
80-
: (['provide'] as const);
78+
const choices: TokenChoice[] = canCreateTokens
79+
? ['provide', 'create', 'auto']
80+
: ['provide'];
8181
const choiceNames = canCreateTokens
8282
? [
8383
'I have a token to provide',

0 commit comments

Comments
 (0)