opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: mcp prompts as slash commands

Open paoloricciuti opened this issue 1 month ago • 16 comments

Partially addresses #806

This adds every prompt in the mcp servers as a slash command...the slashes are named mcp.[servername].[promptname]

Here's how it looks like using it.

https://github.com/user-attachments/assets/89e4819a-292c-47ab-a446-ad66ab6a526a

I've added a "cache" layer so that prompts are only fetched when an MCP server is connected. The value of the prompt is fetched lazily when the user selects it.

If this get's merged, I'll probably work on resources too.

paoloricciuti avatar Dec 12 '25 20:12 paoloricciuti

Yeah ill merge it, maybe have some nits for you but this is good!

rekram1-node avatar Dec 12 '25 21:12 rekram1-node

/review

rekram1-node avatar Dec 12 '25 21:12 rekram1-node

Do we need the dynamic import for mcp?

rekram1-node avatar Dec 12 '25 21:12 rekram1-node

also I wonder if instead of this pattern we should expose ways to add/remove commands on the command namespace and then mcp can just add slash commands / remove them through that?

We kinda have a similar thing for MCP

this is me just glancing over but it's just the way the domains overlap so curious your opinion

rekram1-node avatar Dec 12 '25 21:12 rekram1-node

Do we need the dynamic import for mcp?

In case we don't have any MCP the slash command will always be a normal command. With the dynamic import we will avoid importing the module all together. Not necessary and I'm willing to refactor but seems like a nice addition

paoloricciuti avatar Dec 12 '25 22:12 paoloricciuti

also I wonder if instead of this pattern we should expose ways to add/remove commands on the command namespace and then mcp can just add slash commands / remove them through that?

We kinda have a similar thing for MCP

this is me just glancing over but it's just the way the domains overlap so curious your opinion

We could also do that but it would still require custom logic because the template of the prompt is "special". But yeah I guess it's just a matter of who owns what. You definitely have more experience in the codebase so up to you to take the call. Just let me know and I'll refactor it eventually.

paoloricciuti avatar Dec 12 '25 22:12 paoloricciuti

@rekram1-node shouln not have trusted the review 😅 I actually removed the snake_case now without type errors

paoloricciuti avatar Dec 14 '25 08:12 paoloricciuti

@rekram1-node @paoloricciuti i've tested the original pr against basicmemory and it worked great so far. dependent on an mcp server properly handling prompts in terms of error handling but thats not the problem of the pr implementation. this and getting resources in would be amazing.

kziemski avatar Dec 15 '25 10:12 kziemski

@kziemski glad to hear... I'm gonna work on resources immediately after this gets merged

paoloricciuti avatar Dec 15 '25 11:12 paoloricciuti

planning to merge today

rekram1-node avatar Dec 15 '25 14:12 rekram1-node

Btw I think I have the resource PR basically ready... I'll wait anyway, so this doesn't become a huge PR and there will be fewer conflicts.

paoloricciuti avatar Dec 15 '25 15:12 paoloricciuti

@rekram1-node Just realized: should I also update the documentation?

paoloricciuti avatar Dec 16 '25 14:12 paoloricciuti

merging this today for sure, think I may tweak it a bit but thanks!

rekram1-node avatar Dec 16 '25 22:12 rekram1-node

i lied lol but I will merge today promise, getting back from lunch now then going to pull this down and play w/ it

rekram1-node avatar Dec 17 '25 19:12 rekram1-node

Okay found some bugs, when I do this w/ svelte mcp prompt and don't pass args it just craps out and gets stuck in loading state

rekram1-node avatar Dec 18 '25 05:12 rekram1-node

Uh interesting! Which bugs did you found? Can I do something?

Edit: uh saw the edit...did you fix it? I can do it otherwise... I'd say we just send empty arguments in case...WDYT?

paoloricciuti avatar Dec 18 '25 07:12 paoloricciuti