feat: MCP server for AI clients (v2.15.0, ADR-075)

Add an MCP server at SITE_URL/mcp so AI assistants (claude.ai connectors,
Claude Code) can search, read and write notes.

- starpunk/mcp_server: official MCP SDK 2.3, stateless Streamable HTTP with
  JSON responses, served by uvicorn as a sidecar from the same image.
  Ten tools; writes go through the Micropub handlers.
- IndieAuth: RFC 8707 resource indicators bound to codes and tokens
  (migration 022), client ID metadata document + public client metadata,
  draft in scopes_supported, default MCP scopes, consent screen note.
- BACKGROUND_WORKERS_ENABLED flag so the sidecar runs no workers.
- Docs: ADR-075, architecture/mcp.md and updates; CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-11 16:36:58 -07:00
1 parent 4ed2033cf9
commit 84411a16d9
27 files changed
+1248 -45

No files matched your search

+79 -1
View File
@@ -184,7 +184,9 @@ class TestCodesAndTokens:
with app.test_request_context():
code = create_authorization_code(CLIENT_ID, REDIRECT_URI, "create", challenge_for(verifier))
result = redeem_authorization_code(code, CLIENT_ID, REDIRECT_URI, verifier)
assert result == {"me": "https://example.com", "scope": "create", "client_id": CLIENT_ID}
assert result == {
"me": "https://example.com", "scope": "create", "client_id": CLIENT_ID, "resource": None,
}
token = create_access_token(CLIENT_ID, "create")
info = verify_access_token(token["access_token"])
@@ -354,3 +356,79 @@ class TestEndpoints:
admin_client.post(f"/admin/tokens/{token_id}/revoke")
with app.test_request_context():
assert verify_access_token(token) is None
MCP_RESOURCE = "https://blog.example.com/mcp"
class TestResourceIndicators:
"""RFC 8707 resource binding for MCP clients (v2.15.0, ADR-075)"""
def test_metadata_advertises_cimd_and_draft(self, client):
data = client.get("/.well-known/oauth-authorization-server").get_json()
assert data["client_id_metadata_document_supported"] is True
assert data["token_endpoint_auth_methods_supported"] == ["none"]
assert "draft" in data["scopes_supported"]
def test_mcp_resource_accepted(self, app):
with app.test_request_context():
result = validate_authorization_request(auth_params(resource=MCP_RESOURCE + "/"))
assert result["resource"] == MCP_RESOURCE
def test_no_resource_is_micropub(self, app):
with app.test_request_context():
assert validate_authorization_request(auth_params())["resource"] is None
def test_unknown_resource_rejected(self, app):
with app.test_request_context():
with pytest.raises(AuthorizationRequestError) as e:
validate_authorization_request(auth_params(resource="https://other.example/mcp"))
assert e.value.error == "invalid_target"
assert e.value.redirectable
def test_mcp_client_without_scope_is_offered_defaults(self, app):
with app.test_request_context():
result = validate_authorization_request(auth_params(scope="", resource=MCP_RESOURCE))
assert result["scopes"] == ["create", "update", "delete", "media", "draft"]
def test_consent_page_names_mcp(self, admin_client):
response = admin_client.get("/auth/authorize?" + urlencode(auth_params(resource=MCP_RESOURCE)))
assert response.status_code == 200
assert b"MCP" in response.data
assert b'name="resource" value="https://blog.example.com/mcp"' in response.data
def _token_form(self, query, **extra):
return {
"grant_type": "authorization_code",
"code": query["code"][0],
"client_id": CLIENT_ID,
"redirect_uri": REDIRECT_URI,
"code_verifier": "v" * 50,
**extra,
}
def test_resource_carried_to_token(self, app, admin_client, client):
query = approve(admin_client, granted=["create"], resource=MCP_RESOURCE)
body = client.post("/auth/token", data=self._token_form(query, resource=MCP_RESOURCE)).get_json()
with app.test_request_context():
info = verify_access_token(body["access_token"])
assert info["resource"] == MCP_RESOURCE
assert info["scope"] == "create"
def test_token_request_resource_must_match(self, admin_client, client):
query = approve(admin_client, granted=["create"], resource=MCP_RESOURCE)
response = client.post("/auth/token", data=self._token_form(query, resource="https://other.example/"))
assert response.status_code == 400
assert response.get_json()["error"] == "invalid_target"
def test_micropub_token_has_no_resource(self, app, admin_client, client):
query = approve(admin_client, granted=["create"])
body = client.post("/auth/token", data=self._token_form(query)).get_json()
with app.test_request_context():
assert verify_access_token(body["access_token"])["resource"] is None
def test_legacy_verification_shape_unchanged(self, app, client):
with app.test_request_context():
token = create_access_token(CLIENT_ID, "create", resource=MCP_RESOURCE)["access_token"]
data = client.get("/auth/token", headers={"Authorization": f"Bearer {token}"}).get_json()
assert data == {"me": "https://example.com", "client_id": CLIENT_ID, "scope": "create"}