goose icon indicating copy to clipboard operation
goose copied to clipboard

feat(cli): add mcp prompt support via slash commands

Open kalvinnchau opened this issue 11 months ago • 3 comments

update Prompt structs for align with MCP spec, add basic prompt commands to mcp-client

  • Prompts description and arguments are optional fields, use optional in the structs
    • similarly PromptArguments description and required are optional too
  • add list_prompts and get_prompt method to the McpClientTrait
  • add implementation of list_prompts and get_prompt to call prompts/list and prompts/get respectively
  • update stdio and sse clients to handle JsonRpcMessage::Error responses to send back to the user instead of doing nothing

kalvinnchau avatar Feb 21 '25 01:02 kalvinnchau

nit: you can add a prompt in the mcp-server example here: https://github.com/modelcontextprotocol/rust-sdk/blob/main/crates/mcp-server/src/main.rs. that'll make it easier to test from this mcp-client example: https://github.com/modelcontextprotocol/rust-sdk/blob/main/crates/mcp-client/examples/stdio_integration.rs

salman1993 avatar Feb 21 '25 16:02 salman1993

Moved this back into a draft PR for now, since we're in progress of moving the mcp stuff to the rust-sdk, I'm keeping the commits in sync manually for now but I'll hold off on diverging for nwo.

kalvinnchau avatar Feb 21 '25 19:02 kalvinnchau

Added some basic cli based prompting scaffolding, mainly to list prompts and get the information about them.

Calling the prompt is not yet implemented.

Ex:

( O)> /prompts

 mcp_test
  - no_args_prompt
  - one_arg_prompt
 developer
  - unit_test

( O)> /prompt unit_test --info

 Extension: developer
Prompt: unit_test

 Generate or update unit tests for a given source code file.

The source code file is provided in {source_code}.
Please update the existing tests, ensure they are passing, and add any new tests as needed.

The test suite should:
- Follow language-specific test naming conventions for {language}
- Include all necessary imports and annotations
- Thoroughly test the specified functionality
- Ensure tests are passing before completion
- Handle edge cases and error conditions
- Use clear test names that reflect what is being tested

 Arguments:
  source_code (required) The source code file content to be tested
  language (required) The programming language of the source code

( O)>

With prompt execution support:

/prompt unit_test source_code="~/stage/unit_test/file.py" language=python
# Unit Test Generation and Update

I'll help you generate or update unit tests for the source code file at `~/stage/unit_test/file.py`. First, let me check if this file exists and examine its c
ontents to understand what we need to test.

─── shell | developer ──────────────────────────
command: ls -la ~stage/unit_test/
...

Now, let's run the existing tests to see if they pass:

─── shell | developer ──────────────────────────
command: cd /Users/kalvin/stage/unit_test/ && python -m unittest test_file.py


.....
----------------------------------------------------------------------
Ran 5 tests in 0.005s

OK

Great! The existing tests are already passing. Let's analyze the current test coverage and see if we need to add any additional tests:

...

However, we can enhance the test suite with a few additional tests:

1. Test reading a file with special characters
2. Test reading a file with different encodings
3. Test reading a large file (performance test)

Let's update the test file with these additional tests:

─── text_editor | developer ──────────────────────────
path: ~/stage/unit_test/test_file.py

kalvinnchau avatar Feb 21 '25 19:02 kalvinnchau

https://github.com/user-attachments/assets/f0d7d511-61ce-4b80-8799-4a0305baa842

kalvinnchau avatar Feb 27 '25 20:02 kalvinnchau