Using Prompts
Prompts are reusable templates for LLM interactions defined by the server. They help standardize how agents or users interact with the underlying models.
Listing Prompts
Access available prompts via the prompts array.
const { prompts } = useMcp({ url: '...' });
// Display prompts
{prompts.map(p => (
<div key={p.name}>
<h3>{p.name}</h3>
<p>{p.description}</p>
</div>
))}
Getting a Prompt
To use a prompt, you "get" it from the server, optionally passing arguments. The server renders the template and returns messages ready for an LLM.
const { getPrompt } = useMcp({ url: '...' });
const loadPrompt = async () => {
try {
// Arguments map string keys to string values
const result = await getPrompt('review_code', {
code: 'console.log("foo")',
language: 'javascript'
});
// result.messages contains the role/content array
console.log(result.messages);
} catch (error) {
console.error('Failed to load prompt:', error);
}
};