feat(cli/mcp): add slash command prompts (/sessions, /spend) and updating docs - #4
Conversation
- Register 'sessions' and 'spend' MCP prompts so clients like Claude Code
surface /mcp__agentmeter__sessions and /mcp__agentmeter__spend as slash
commands; both accept optional string args (limit / days) and embed live
data directly into the prompt message for instant context
- Add prompts:{} to server capabilities
- README: add slash commands table, add Updating section covering npx @latest
vs global install and the restart-after-update note
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
There was a problem hiding this comment.
Review
The README additions and MCP prompt structure look good — the slash command descriptions are accurate, the as const casts are correct, and the optional chaining on result.content[0]?.text properly handles noUncheckedIndexedAccess.
One issue to fix before merging: both prompt handler bodies await functions that touch the filesystem (handleListRecentSessions) or the network (handleGetMySpend) with no try/catch. Per CLAUDE.md, the CLI must never crash with an unhandled exception. Add a try/catch in each handler and return a graceful error message string — the MCP SDK can surface it to the client rather than the server crashing or returning a protocol-level error.
Generated by Agent: Code Review for issue #4 · ● 99.7K
| async ({ limit }) => { | ||
| const limitNum = limit ? Math.min(50, Math.max(1, Number.parseInt(limit, 10) || 10)) : 10; | ||
| const result = await handleListRecentSessions({ limit: limitNum }); | ||
| const data = result.content[0]?.text ?? '{}'; | ||
| return { | ||
| messages: [ | ||
| { | ||
| role: 'user' as const, | ||
| content: { | ||
| type: 'text' as const, | ||
| text: `Here are my ${limitNum} most recent AI coding sessions:\n\n${data}\n\nPlease summarise what I have been working on, call out any sessions that used an unusually high number of tokens, and give me the total token count across all sessions shown.`, | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
| }, |
There was a problem hiding this comment.
Missing error handling — handleListRecentSessions involves file I/O and can throw. Per CLAUDE.md: "the CLI should never crash with an unhandled exception. Catch, log, continue."
Wrap the handler body in try/catch and return a graceful message on failure:
async ({ limit }) => {
try {
const limitNum = limit ? Math.min(50, Math.max(1, Number.parseInt(limit, 10) || 10)) : 10;
const result = await handleListRecentSessions({ limit: limitNum });
const data = result.content[0]?.text ?? 'No session data available.';
return {
messages: [{
role: 'user' as const,
content: { type: 'text' as const, text: `Here are my \$\{limitNum} most recent AI coding sessions:\n\n\$\{data}\n\n...` },
}],
};
} catch (err) {
return {
messages: [{
role: 'user' as const,
content: { type: 'text' as const, text: `Failed to fetch sessions: \$\{String(err)}` },
}],
};
}
},| async ({ days }) => { | ||
| const daysNum = days ? Math.min(365, Math.max(1, Number.parseInt(days, 10) || 7)) : 7; | ||
| const result = await handleGetMySpend({ days: daysNum }); | ||
| const data = result.content[0]?.text ?? '{}'; | ||
| return { | ||
| messages: [ | ||
| { | ||
| role: 'user' as const, | ||
| content: { | ||
| type: 'text' as const, | ||
| text: `Here is my AI coding spend data for the last ${daysNum} day${daysNum === 1 ? '' : 's'}:\n\n${data}\n\nPlease summarise my spending trends, highlight any notable spikes or patterns, and give me a sense of whether my usage is tracking high or low.`, | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
| }, |
There was a problem hiding this comment.
Same missing error handling as the sessions handler — handleGetMySpend makes a network call and can throw. Same fix applies: wrap in try/catch and return a message on error rather than letting it propagate.
Summary
Adds two MCP prompts so Claude Code and Cursor surface explicit slash commands, plus an Updating section in the README.
Slash commands
/mcp__agentmeter__sessionssessionslimit(optional, default 10)/mcp__agentmeter__spendspenddays(optional, default 7)Both prompts fetch live data via the existing handler functions and embed it directly in the user message — Claude has the data in context immediately without needing to decide to call a tool.
sessionsworks with no account.spendreturns the no-key hint gracefully if no API key is configured.README: Updating section
Covers three scenarios:
@agentmeter/cli@latestin config args — npx re-resolves on cache expirynpm install -g @agentmeter/cli@latestto update, useagentmeteras commandRelease
Merge and create a release with title
feat(cli/mcp): add slash command promptsto trigger a minor bump →1.1.0.