This guide walks you through securing the Solr MCP server's HTTP transport with
Auth0: register an API and a machine-to-machine
application, mint an access token, run the server, verify it, and connect an
MCP client. Companion to keycloak.md; the server-side model
is in http.md.
- Create Auth0 Application
- Create Auth0 API
- Authorize the Application for the API
- Get an Access Token
- Run the Server
- Verify
- Connect an MCP Client
- Convenience Script for Getting Access Tokens
- Application Configuration Details
- Troubleshooting
- Security Best Practices
The server validates the token's aud claim against its resource URI,
which it derives from the URL the client calls — scheme, host and port plus
/mcp. For a local trial that is http://localhost:8080/mcp; for a deployed
server it is the public URL, e.g. https://mcp.example.com/mcp. Read it from a
running server with:
curl -s http://localhost:8080/.well-known/oauth-protected-resource | jq -r .resource
# http://localhost:8080/mcpAuth0 puts the API Identifier into aud, so the Identifier you choose in
step 2 must be that URI, spelled exactly as clients will dial it. Auth0 never
calls the URL; it only has to match. A token for any other identifier (the
https://solr-mcp-api style Auth0 suggests) is rejected with
401 ... "The aud claim is not valid".
- Go to Auth0 Dashboard
- Log in with your credentials
- Navigate to Applications > Applications in the left sidebar
- Click Create Application
- Enter application details:
- Name:
Solr MCP Server(or your preferred name) - Application Type: Select Machine to Machine Applications
- Name:
- Click Create
A machine-to-machine application uses the Client Credentials grant: it obtains tokens with its client ID and secret, with no browser login. That is the right shape for trying the server from a terminal or from an MCP client that takes a bearer token.
After creation, you'll see the application settings page. Note down:
- Domain:
your-tenant.auth0.com(found at the top of the page) - Client ID: A unique identifier for your application
- Client Secret: Keep this secure, it's like a password
- In the Auth0 Dashboard, go to Applications > APIs
- Click Create API
- Enter API details:
- Name:
Solr MCP API(or your preferred name) - Identifier:
http://localhost:8080/mcp— the server's resource URI (see Before you start). For a deployed server use its public URL, e.g.https://mcp.example.com/mcp. - Signing Algorithm: Leave as RS256 (recommended)
- Name:
- Click Create
- Go to the Permissions tab
- Add scopes if needed (e.g.,
read:schema,write:documents) - For basic setup, you can skip this and add permissions later. The shipped
server checks
isAuthenticated()only; scopes are not evaluated.
- Go back to Applications > Applications
- Click on your Solr MCP Server application
- Open the APIs tab
- Find your Solr MCP API and click the toggle to authorize it
- Select the permissions/scopes you want to grant (or select all)
- Click Update
No callback or logout URLs are needed: the MCP server is a resource server, it never redirects a browser to Auth0, and a machine-to-machine application does not use the authorization-code flow.
curl --request POST \
--url https://YOUR_DOMAIN/oauth/token \
--header 'content-type: application/json' \
--data '{
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"audience": "http://localhost:8080/mcp",
"grant_type": "client_credentials"
}'Replace:
YOUR_DOMAIN: Your Auth0 domain (e.g.,your-tenant.auth0.com)YOUR_CLIENT_ID: Your application's Client IDYOUR_CLIENT_SECRET: Your application's Client Secretaudience: Your API identifier from step 2
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6...",
"token_type": "Bearer",
"expires_in": 86400
}TOKEN=$(curl -s --request POST --url https://YOUR_DOMAIN/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET",
"audience":"http://localhost:8080/mcp","grant_type":"client_credentials"}' \
| jq -r .access_token)
jwt_payload() {
python3 -c "import sys,base64,json;p=sys.argv[1].split('.')[1];p+='='*(-len(p)%4);\
print(json.dumps(json.loads(base64.urlsafe_b64decode(p))))" "$1"
}
jwt_payload "$TOKEN" | jq '{iss, aud}'
# { "iss": "https://your-tenant.auth0.com/", "aud": "http://localhost:8080/mcp" }iss ends with a slash; OAUTH2_ISSUER_URI in the next step must match it
character for character.
The HTTP profile is secured by default; the only value you have to supply is
the issuer. Pass the environment inline rather than exporting it — an
exported OAUTH2_ISSUER_URI is inherited by the Gradle daemon and breaks the
next ./gradlew build.
PROFILES=http \
OAUTH2_ISSUER_URI=https://your-tenant.auth0.com/ \
./gradlew bootRunOr with the fat JAR or the Docker image:
PROFILES=http OAUTH2_ISSUER_URI=https://your-tenant.auth0.com/ \
java -jar build/libs/solr-mcp-1.0.0-SNAPSHOT.jar
docker run -p 8080:8080 --rm \
-e PROFILES=http \
-e OAUTH2_ISSUER_URI=https://your-tenant.auth0.com/ \
-e SOLR_URL=http://host.docker.internal:8983/solr/ \
solr-mcp:latestThe issuer URI must end with a trailing slash /, because that is how
Auth0 writes the iss claim. The server resolves
https://your-tenant.auth0.com/.well-known/openid-configuration at startup
and exits if it cannot; a wrong domain fails immediately, not on the first
request.
The server is ready when curl http://localhost:8080/actuator/health answers
{"status":"UP"}.
An unauthenticated tool call is denied inside the tool (HTTP 200, JSON-RPC
error); the same call with the token returns data. That contrast is the check
that the gate is live:
# Without a token → "Access Denied"
curl -s -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","method":"tools/call","id":1,"params":{"name":"list-collections","arguments":{}}}'
# {"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"Access Denied"}],"isError":true}}
# With the token → the collections
curl -s -X POST http://localhost:8080/mcp \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","method":"tools/call","id":2,"params":{"name":"list-collections","arguments":{}}}'
# {"jsonrpc":"2.0","id":2,"result":{"content":[{"type":"text","text":"[\"books\",\"films\"]"}],"isError":false}}To see why a token is rejected, ask a protected actuator endpoint, which
answers with a plain 401 and the reason:
curl -s -i -H "Authorization: Bearer $TOKEN" http://localhost:8080/actuator/metrics | grep -i www-authenticate
# 200 and no header → token valid
# ... error_description="... The aud claim is not valid" → wrong API identifier / wrong URL spelling
# ... error_description="... Jwt expired at ..." → request a new tokenThe server does not answer an anonymous /mcp request with 401 — /mcp is
permitted at the HTTP layer and the denial happens inside each tool — and MCP
clients start their OAuth flow only on a 401. A client configured with just
the URL therefore shows the server as connected, lists every tool, and gets
Access Denied from every call. Pass the token explicitly:
# Claude Code
claude mcp add --transport http solr-mcp http://localhost:8080/mcp \
--header "Authorization: Bearer $TOKEN"
# MCP Inspector, CLI
npx @modelcontextprotocol/inspector --cli http://localhost:8080/mcp --transport http \
--header "Authorization: Bearer $TOKEN" --method tools/call --tool-name list-collections
# MCP Inspector, web UI
npx @modelcontextprotocol/inspector --server-url http://localhost:8080/mcp --transport http \
--header "Authorization: Bearer $TOKEN"The other clients take the same header — the table in
http.md covers
Claude Desktop and JetBrains via mcp-remote, VS Code, Cursor and Zed, and
each client guide shows the full snippet. Auth0
machine-to-machine tokens last 24 hours by default (expires_in: 86400);
when one expires, re-add the server with a fresh token.
A convenience script scripts/get-auth0-token.sh is provided to automate token retrieval for testing and development.
The script requires the following configuration (can be provided via environment variables, .env file, or command-line
arguments):
# Auth0 Token Script Configuration
AUTH0_DOMAIN=your-tenant.auth0.com
AUTH0_CLIENT_ID=your-client-id-here
AUTH0_CLIENT_SECRET=your-client-secret-here
AUTH0_AUDIENCE=http://localhost:8080/mcpUsing .env file:
# Create .env file with the above configuration
./scripts/get-auth0-token.shUsing command-line arguments:
./scripts/get-auth0-token.sh \
--domain your-tenant.auth0.com \
--client-id YOUR_CLIENT_ID \
--client-secret YOUR_CLIENT_SECRET \
--audience http://localhost:8080/mcpGet just the token (for scripting):
TOKEN=$(./scripts/get-auth0-token.sh --quiet)
echo "Authorization: Bearer $TOKEN"Save to custom file:
./scripts/get-auth0-token.sh --output my-token.txtThe script will:
- Request an access token from Auth0 using Client Credentials flow
- Display the token and expiration time
- Save the token to
.auth-tokenfile (with secure 600 permissions)
No file edits are required; the environment variables above are enough. For
reference, the relevant entries in src/main/resources/application-http.properties:
# Security toggle — HTTP mode is secured by default.
http.security.enabled=${HTTP_SECURITY_ENABLED:true}
# OAuth2 issuer. Empty by default: the filter chain then answers 401/403 to
# everything except /actuator/health instead of crashing on a placeholder.
spring.security.oauth2.resourceserver.jwt.issuer-uri=${OAUTH2_ISSUER_URI:}Key Points:
- OAuth2 is only active when using the
httpprofile - The default profile is
stdiowhich does not use OAuth2 - The server validates the JWT signature (against the issuer's JWKS), issuer,
expiry and audience — the
audclaim must contain the server's resource URI (seehttp.md) HTTP_SECURITY_ENABLED=falseturns authentication off for a local experiment; never on anything reachable by other people- CORS allows the MCP Inspector's origin by default (
MCP_CORS_ALLOWED_ORIGINS) - CSRF is disabled because the API is stateless bearer-token
-
401withThe aud claim is not valid- The API Identifier is not the server's resource URI. Compare
jwt_payload "$TOKEN" | jq .audwithcurl -s http://localhost:8080/.well-known/oauth-protected-resource | jq -r .resource - The client dials the server under a different name than the one in the
token (
127.0.0.1vslocalhost, or a public hostname). Use the same spelling everywhere
- The API Identifier is not the server's resource URI. Compare
-
401withJwt expired at ...- Request a new token; the default lifetime is 24 hours
-
Server exits at startup with
Unable to resolve the Configuration with the provided IssuerOAUTH2_ISSUER_URIis wrong or lacks the trailing slash, or the machine cannot reach Auth0. Check withcurl https://your-tenant.auth0.com/.well-known/openid-configuration
-
access_denied/Unauthorizedfrom the token endpoint- Verify Client ID and Client Secret are correct
- Ensure the application is authorized for the API (step 3)
-
Every tool call returns
Access Deniedfrom an MCP client, no browser opens- Expected when the client sends no token: the server does not challenge
/mcpwith401, so the client never starts OAuth. Configure the header as in step 7
- Expected when the client sends no token: the server does not challenge
- Never commit secrets: Use environment variables or secure vaults
- Rotate credentials: Regularly rotate Client Secrets
- Use HTTPS in production: Never use http:// for production callbacks
- Limit scopes: Grant only necessary permissions
- Monitor usage: Use Auth0 Dashboard to monitor authentication attempts
- Set token expiration: Configure appropriate token lifetimes