Repository navigation
Conversation
…nnel client (port of PR HEXUXIU#48 to main) Port of the PR HEXUXIU#48 work rebased onto the refactored main branch, as requested in the last review round. resources API (was never implemented; tests added earlier did not build): - Resource / ResourceContent / ResourceProvider types - RWMutex-guarded global provider (resourceProvider() / SetGlobalResourceProvider) — safe for concurrent swap - resources/list + resources/read RPC handlers - SSRF guard: scheme allowlist (mcp:// gateway:// m365://) PLUS a check that the URI was advertised via resources/list, so reads are tied to the enumerated surface. TODO(perf) notes the O(n) scan is acceptable at current scale with ResourceExists as the escape hatch. - initialize now advertises the resources capability Error-message hygiene: - provider errors and raw unmarshal errors are logged server-side; clients get generic messages only - resource-not-found (-32002) no longer echoes the requested URI — it is logged instead Auth: - HandleSSE / HandleMessage now enforce APIKeyValidator (same variable HandleToolsList already uses; wired once in Routes()). No new hook variable. readSSE on the new pending map[int64]chan model: - non-blocking send is kept deliberately: each pending channel has capacity 1 and exactly one select-waiting consumer, so a full channel means the requester timed out. Blocking would stall the SSE reader for a response nobody will read. The drop path now logs. - client_sse_test.go rewritten for this model: late-response drop must not block, waiter delivery works, id-less notifications are skipped. The session_resolver reverse-index work from the original PR is dropped: main's Tenant/ExplicitID refactor already resolves byExplicit cleanup correctly.
Owner
|
感谢提交!但项目方向已调整:对外只保留 Web 控制台与三套标准接口(OpenAI Chat/Responses、Anthropic Messages),不再对外暴露 MCP。MCP 仅用于内部把标准工具调用转换为 M365 官方通道。因此本 PR 不再适用,故关闭。 |
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
Port of #48 onto the current
main, as requested in the last review round (the old branch targeteddevbefore themsgCh → pending map[int64]chanclient refactor and no longer applied).Supersedes #48.
1. MCP resources API was never implemented
Ports the implementation, adapted to main:
Resource/ResourceContent/ResourceProvidertypesresourceProvider()/SetGlobalResourceProvider()— safe for concurrent swapresources/list+resources/readhandlers;initializenow advertises theresourcescapabilitymcp://,gateway://,m365://) plus a check that the URI was actually advertised byresources/list, so reads are tied to the enumerated surface and cannot probe arbitrary targets. ATODO(perf)documents that the O(n) scan is acceptable at current scale, withResourceExists(ctx, uri)as the future escape hatch.2. Error-message hygiene
resources/read404 (-32002) no longer echoes the requested URI back to the client — it is logged instead3. Endpoint auth unified on
APIKeyValidatorHandleSSEandHandleMessagenow enforceAPIKeyValidator— the same variableHandleToolsListalready uses, wired once inRoutes(). No new hook variable orinitMCPAuth; the oldAuthHookdesign from #48 is gone.4. readSSE on the new per-request channel model
The original PR's bounded-blocking-send (timer reuse) is intentionally not ported: in the
pending map[int64]chanmodel each channel has capacity 1 with exactly one select-waiting consumer, so a full channel means the requester already timed out. Blocking there would stall the SSE reader for a response nobody will ever read. The drop path now logs why.The session_resolver reverse-index work from #48 is dropped: main's
Tenant/ExplicitIDrefactor already handlesbyExplicitcleanup correctly.Testing
New/ported tests:
TestResourcesListReturnsRegisteredResources,TestResourcesReadReturnsContent,TestInitializeAdvertisesResourcesCapabilityTestResourcesReadRejectsUnlistedURI(SSRF: unlisted-but-allowed-scheme rejected, disallowed scheme rejected, listed URI readable)client_sse_test.gorewritten for the pending model: late response drops without blocking, waiter delivery works, id-less notifications are skipped