Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 16 commits into from
Feb 27, 2025

Conversation

kalvinnchau
Copy link
Collaborator

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

- add new endpoints `list_prompts` and `get_prompt` in the MCP client
- update prompt model in mcp-core to make `description` and `arguments`
  optional, following MCP spec
@@ -70,9 +70,9 @@ pub fn load_prompt_files() -> HashMap<String, Prompt> {
description: arg.description,
required: arg.required,
})
.collect();
.collect::<Vec<PromptArgument>>();
Copy link
Collaborator

@salman1993 salman1993 Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to this PR: i don't think we need this mapping - https://github.com/block/goose/blob/main/crates/goose-mcp/src/developer/prompts/unit_test.json

it'd be easier to stay closer to the MCP prompt in the json to avoid this mapping (description instead of template)

@salman1993
Copy link
Collaborator

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

…e implementing types to define them, similar to other methods
- extend CLI input handling to support `/prompts` for listing available prompts
- add `ListPrompts` variant in the input enum and update help documentation
- implement prompt rendering in the session output module
- update agent traits and capabilities to aggregate and list prompts from all extensions
@kalvinnchau kalvinnchau marked this pull request as draft February 21, 2025 19:09
@kalvinnchau
Copy link
Collaborator Author

kalvinnchau commented Feb 21, 2025

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
Copy link
Collaborator Author

kalvinnchau commented Feb 21, 2025

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 and others added 4 commits February 25, 2025 14:28
agent loop

Add functionality to transform PromptMessageContent to MessageContent
with proper handling in the session module and add test coverage.
Add the results of GetPrompt to the message conversation and run the
agent loop with prompt response.
fix: update process_agent_response call
@lily-de lily-de mentioned this pull request Feb 26, 2025
2 tasks
@kalvinnchau kalvinnchau changed the title feat: update mcp-core prompt to match spec, add mcp list/get to mcp-client feat(cli): add mcp prompt support via slash commands Feb 26, 2025
@kalvinnchau kalvinnchau marked this pull request as ready for review February 26, 2025 18:40
* main:
  feat: allow user to turn off smart approve (#1407)
  feat: Read .gooseignore to Restrict access to files or Directories (#1199)
  docs: adding update command to cli command guide (#1411)
  docs: Adding YT short for Computer Controller Tutorial (#1420)
  feat(cli): support arbitrary path for sessions (#1414)
  feat: remove the disable state from chat input box (#1341)
  feat: Add extra details to prompt for gui (#1387)
  style: added launch text and styling (#1406)
  fix(docs): update default session location (#1412)
  feat: moved extension add button and updated label (#1408)
  draft: use rust messages in typescript (#1393)
  fix: detect read only tool when only mode is approve (#1398)
  docs: Add Puppeteer Extension Tutorial (#1396)
  chore(release): release version v1.0.10 (#1404)
  chore(release): release 1.10.0  (#1385)
  feat: wip on ConfigProvider and integration in settings_v2 (#1395)
  feat: Add command `goose update` to update goose CLI version (#1308)
@kalvinnchau
Copy link
Collaborator Author

Screen.Recording.2025-02-27.at.12.37.09.PM.mov

Ok(None)
}

pub async fn get_prompt(&mut self, name: &str, arguments: Value) -> Result<Vec<PromptMessage>> {
Copy link
Collaborator

@salman1993 salman1993 Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we invoked a PromptMessage that starts with assistant role - i think that would error because the CLI assumes its user msg and we also need to alternate between user & assistant. can you check this? if so, we might wanna enforce some checks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added enforcement for user first, and that the messages alternate user & assistant

- render user messages to the user's session
- enforce user-assistant-user pattern and cleanup with bad patterns
@kalvinnchau kalvinnchau merged commit d0ca469 into main Feb 27, 2025
6 checks passed
@kalvinnchau kalvinnchau deleted the kalvin/mcp-prompt branch February 27, 2025 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants