fix(resources/prompts): list correctly; add resource read, prompt get, and Type column#244
Open
dariushoule wants to merge 3 commits into
Open
fix(resources/prompts): list correctly; add resource read, prompt get, and Type column#244dariushoule wants to merge 3 commits into
dariushoule wants to merge 3 commits into
Conversation
…turn typed objects ToolManager.list_resources and list_prompts were synchronous stubs that returned the un-awaited coroutine from the (async) StreamManager and never converted the result. The resources/prompts commands await these methods and access attributes (resource.id, prompt.name, ...), so listing always ended in "No resources available." / "No prompts available." — and would raise AttributeError on a dict once data was actually available. - Make both methods async, await the StreamManager, and convert each raw dict via ResourceInfo.from_raw (already existed) / PromptInfo.from_raw. - Add a PromptInfo model mirroring ResourceInfo. - Update the ToolManager unit tests to the async + typed-object contract; they previously asserted the buggy synchronous passthrough. The existing command tests already mock these methods as async returning ResourceInfo objects, i.e. this aligns the manager with the contract the rest of the codebase already assumes. Signed-off-by: Darius Houle <darius@x64.ooo>
- Add `mcp-cli resources --read <uri>` (and a `read` parameter for chat / interactive modes) to print a resource's contents, wiring up the existing ToolManager.read_resource which previously had no CLI/chat surface. - ResourceInfo.from_raw now normalizes MCP's `uri` -> id and `mimeType` -> type so the resources table's Type column is populated instead of always "unknown"; the original keys are preserved in `extra`. - Tests: ResourceInfo.from_raw normalization cases, PromptInfo unit tests, and `resources --read` command tests (success + not-found). Signed-off-by: Darius Houle <darius@x64.ooo>
Wire ToolManager.get_prompt (delegating to StreamManager.get_prompt) and implement the prompts command's existing `get` parameter plus the `mcp-cli prompts --get` CLI option, rendering the returned messages. Symmetric to `resources --read`. Tests: ToolManager.get_prompt (no-manager / success / error); prompts `--get` command tests (renders messages; missing prompt -> failure). Signed-off-by: Darius Houle <darius@x64.ooo>
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
mcp-cli resourcesandmcp-cli promptsalways print "No resources available." /"No prompts available." even when the server exposes them; there is no way to read
a resource or fetch a prompt; and the resources table's Type column always shows
unknown. This PR fixes all of it.1. Listing always empty (root cause)
ToolManager.list_resources/list_promptswere synchronous stubs that returned theun-awaited coroutine from the (async)
StreamManagerand never converted the result, sothe commands (which
awaitthem and accessresource.id/prompt.name) always sawnothing — and would
AttributeErroron a dict once data was available. Contrastget_all_tools, which already awaits and converts toToolInfo.Fix: make both
async,awaitthe StreamManager, and convert each raw dict to a typedobject —
ResourceInfo.from_raw(existed) / a newPromptInfomodel.2. Read a resource / fetch a prompt
ToolManager.read_resourceexisted but had no CLI/chat surface, and there was noget_promptpath at all.Fix:
mcp-cli resources --read <uri>— print a resource's contents.mcp-cli prompts --get <name>— fetch and render a prompt's messages (addsToolManager.get_prompt; the prompts command already declared agetparameter that wasnever implemented).
(Both also work as the
read/getparameters in chat and interactive modes.)3. Type column always "unknown"
The command read
resource.type or resource.extra.get("mime_type"), but MCP resources usemimeType(and are identified byuri).Fix:
ResourceInfo.from_rawnormalizesuri→idandmimeType→type(originalspreserved in
extra), so the Type column is populated.Tests
ToolManager.list_resources/list_prompts/get_promptrewritten/added to the async + typedcontract (the previous list tests asserted the buggy synchronous passthrough).
ResourceInfo.from_rawnormalization cases + newPromptInfounit tests.resources --readandprompts --getcommand tests (success + not-found).list_resources/list_promptsasasyncreturningResourceInfoobjects — this aligns the implementation with that contract — and still pass.tests/tools+tests/commands/definitions) all green. (Unrelatedpre-existing Windows-console
charmapfailures in chat-banner tests are untouched.)Companion fix
End-to-end output depends on
chuk-tool-processorreturning the data: its stdio/HTTPtransports discard the pydantic
*Resultmodels, andStreamManagerlackedget_prompt.Both are fixed in IBM/chuk-tool-processor#45. With that plus this PR,
mcp-cli resourcesand
promptslist, read/get, and show types correctly.