fix: normalize trailing slashes in UMBRACO_BASE_URL (#63)#64
Merged
Conversation
When UMBRACO_BASE_URL was configured with (or without) a trailing slash,
the URL concatenation in the SDK and hosted-mcp fetch clients produced
malformed request URLs ("//" or edge-case path joining), which caused
token exchange and API calls to fail without a clear error.
Normalize baseUrl at the HTTP client entry points so both forms behave
identically:
- SDK `initializeUmbracoFetch` and `createUmbracoFetchClient().initialize`
strip trailing slashes before storing the auth config
- Hosted-mcp `createUmbracoFetchClient` normalizes once at setup
Adds focused unit tests covering no / one / multiple trailing slashes in
both packages.
Closes #63
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Code-review follow-ups on the trailing-slash fix: - Extract `normalizeBaseUrl(url)` to `@umbraco-cms/mcp-server-sdk` (`helpers/url.ts`, exported from main + helpers entry points) and use it from the SDK and hosted-mcp fetch clients - Replace `getBackofficeEndpoints` inline `/\/$/` (single-slash only — latent bug for inputs like `https://x//`) with the same helper - `initializeUmbracoFetch` now clears the cached access token, so a re-init with a different base URL can't reuse a stale token - Drop redundant `mockFetch.mockReset()` calls inside `it.each` bodies (already covered by the suite's `beforeEach`) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
hifi-phil
added a commit
that referenced
this pull request
Apr 26, 2026
Changes since 17.0.0-beta.14:
- feat(sdk): ship per-tool TypeScript types codegen (#65, #66)
Adds a `umbraco-mcp-generate-types` postbuild step that walks
`dist/collections.js`, runs each tool's input/output Zod schema
through codegen, and writes a typed registry to
`dist/tool-types.d.ts`. Exposed via the `./tool-types` subpath
so downstream MCPs can chain to a built server with full type
safety (`import type { McpTemplateTools } from "@umbraco-cms/mcp-template/tool-types"`).
- fix: normalize trailing slashes in UMBRACO_BASE_URL (#63, #64)
Strips a trailing `/` from `UMBRACO_BASE_URL` before joining
paths, so values like `https://example.com/` no longer produce
`//umbraco/management/api/...` request URLs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #63.
When
UMBRACO_BASE_URLwas configured with or without a trailing slash, the URL concatenation in the SDK and hosted-mcp fetch clients could produce malformed request URLs (double slashes or edge-case path joining), causing token exchange and API calls to fail without a clear error message.Normalize
baseUrlat the HTTP client entry points so both forms behave identically:initializeUmbracoFetchandcreateUmbracoFetchClient().initializestrip trailing slashes before storing the auth configcreateUmbracoFetchClientnormalizes once at setupPaths produced by the Orval-generated clients already start with a leading
/, so stripping trailing slashes onbaseUrlyields correct URLs for every combination.Tests
packages/mcp-server-sdk/src/http/__tests__/base-url-normalization.test.ts— 6 tests covering no / one / multiple trailing slashes against both the singleton and factory clientspackages/hosted-mcp/src/http/__tests__/umbraco-fetch-client.test.ts— 3 additional parameterized cases againstcreateUmbracoFetchClientLocal verification
npm test(SDK unit + stdio)npm test -w packages/hosted-mcpTest plan
dev, include in next beta release🤖 Generated with Claude Code