WeKnora/internal/mcp
Ochan Kwon 8af7938aed
fix(mcp): keep OAuth token expiry independent of the process time zone (#4207)
* fix(mcp): keep OAuth token expiry independent of the process time zone

mcp_oauth_tokens.expires_at is a naive TIMESTAMP column. The token store
computes the expiry from the process clock, the column drops its offset,
and the driver reads the stored wall clock back as UTC. When the
application runs outside UTC, every stored expiry is therefore shifted
by the process offset: with TZ=Asia/Shanghai, the docker compose default,
a token is reported as expiring eight hours after it really does.

WeKnora trusts that value. The OAuth status endpoint reports a token as
authorized for those extra hours, and the runtime neither refreshes it
ahead of time nor asks for authorization again. It sends the expired
access token to the MCP server and only recovers after the server
rejects it.

Promote the token and client timestamps to TIMESTAMP WITH TIME ZONE, as
migration 000072 did for API keys and resource grants, and normalize the
values the repository writes to UTC, so new rows are right even before
the migration is applied. The status endpoint keeps reporting the expiry
in UTC as before: the driver returns timestamptz values in the process
time zone, and the response would otherwise vary by deployment.

The migration cannot repair existing rows, because the time zone of the
process that wrote them is unknown. Like 000072, it reads them as UTC,
so they keep their shifted value until the token is authorized or
refreshed again.

* fix(migrations): renumber MCP OAuth timestamptz migration to 000118

000117 is now taken on main by messages_attachment_lookup.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-13 16:56:51 +08:00
..
client.go feat(mcp): let callers without a browser obtain MCP OAuth tokens (#4229) 2026-10-13 16:37:24 +08:00
client_param_headers_test.go feat(mcp): support 2026-07-28 alongside legacy clients (#4095) 2026-10-10 15:15:06 +08:00
client_protocol_test.go feat(mcp): support 2026-07-28 alongside legacy clients (#4095) 2026-10-10 15:15:06 +08:00
client_resources_test.go fix(mcp): ignore discover probe in resource list tests (#4179) 2026-10-12 14:53:16 +08:00
client_session_test.go feat(mcp): support 2026-07-28 alongside legacy clients (#4095) 2026-10-10 15:15:06 +08:00
client_structured_result_test.go fix(mcp): preserve structured tool results for agents 2026-10-10 20:27:34 +08:00
client_test.go feat(mcp)!: persist tool catalogs and add guided configuration (#3118) 2026-09-09 13:34:56 +08:00
client_tools_test.go feat(mcp): support 2026-07-28 alongside legacy clients (#4095) 2026-10-10 15:15:06 +08:00
errors.go refactor: Clean up code by removing unnecessary blank lines and improving comments for better readability and maintainability 2025-11-28 16:10:37 +08:00
manager.go fix(mcp): close only the authorizing user's connection after OAuth (#4138) 2026-10-12 11:19:42 +08:00
manager_close_principal_test.go fix(mcp): close only the authorizing user's connection after OAuth (#4138) 2026-10-12 11:19:42 +08:00
manager_closeall_test.go fix(mcp): close MCP connections on shutdown without blocking exit 2026-09-25 18:22:14 +08:00
manager_disconnect_test.go fix(mcp): 隔离慢连接清理对其他服务的阻塞 2026-10-10 20:12:58 +08:00
manager_startup_test.go feat(mcp): support 2026-07-28 alongside legacy clients (#4095) 2026-10-10 15:15:06 +08:00
oauth_assertion.go feat(mcp): let callers without a browser obtain MCP OAuth tokens (#4229) 2026-10-13 16:37:24 +08:00
oauth_assertion_test.go feat(mcp): let callers without a browser obtain MCP OAuth tokens (#4229) 2026-10-13 16:37:24 +08:00
oauth_lifecycle.go fix(mcp): keep OAuth token expiry independent of the process time zone (#4207) 2026-10-13 16:56:51 +08:00
oauth_lifecycle_test.go fix(mcp): keep OAuth token expiry independent of the process time zone (#4207) 2026-10-13 16:56:51 +08:00
oauth_manager.go feat(mcp): let callers without a browser obtain MCP OAuth tokens (#4229) 2026-10-13 16:37:24 +08:00
oauth_manager_test.go fix(mcp): close only the authorizing user's connection after OAuth (#4138) 2026-10-12 11:19:42 +08:00
oauth_preregistered_client_test.go feat(mcp): let callers without a browser obtain MCP OAuth tokens (#4229) 2026-10-13 16:37:24 +08:00
oauth_principal_test.go fix(mcp): coordinate OAuth token refresh and authorization polling 2026-07-23 15:35:24 +08:00
oauth_redirect_security_test.go fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
oauth_state.go fix(mcp): coordinate OAuth token refresh and authorization polling 2026-07-23 15:35:24 +08:00
oauth_state_test.go fix(mcp): coordinate OAuth token refresh and authorization polling 2026-07-23 15:35:24 +08:00
oauth_tokenstore.go fix(mcp): coordinate OAuth token refresh and authorization polling 2026-07-23 15:35:24 +08:00
security.go fix(security): harden outbound URL SSRF protection (#2626) 2026-08-10 13:24:14 +08:00
security_test.go fix(security): harden outbound URL SSRF protection (#2626) 2026-08-10 13:24:14 +08:00
tool_content_test.go fix(mcp): pass embedded resources in tool results to the agent (#3766) 2026-10-08 01:25:04 +08:00
types.go fix(mcp): preserve structured tool results for agents 2026-10-10 20:27:34 +08:00