Skip to content

feat(cli/mcp): add slash command prompts (/sessions, /spend) and updating docs - #4

Merged
adamhenson merged 1 commit into
mainfrom
cursor/mcp-prompts-395b
Jul 24, 2026
Merged

feat(cli/mcp): add slash command prompts (/sessions, /spend) and updating docs#4
adamhenson merged 1 commit into
mainfrom
cursor/mcp-prompts-395b

Conversation

@adamhenson

Copy link
Copy Markdown
Contributor

Summary

Adds two MCP prompts so Claude Code and Cursor surface explicit slash commands, plus an Updating section in the README.

Slash commands

Slash command Prompt name Args
/mcp__agentmeter__sessions sessions limit (optional, default 10)
/mcp__agentmeter__spend spend days (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.

sessions works with no account. spend returns the no-key hint gracefully if no API key is configured.

README: Updating section

Covers three scenarios:

  • @agentmeter/cli@latest in config args — npx re-resolves on cache expiry
  • Global install — npm install -g @agentmeter/cli@latest to update, use agentmeter as command
  • Restart-after-update note (MCP servers are not hot-reloaded)

Release

Merge and create a release with title feat(cli/mcp): add slash command prompts to trigger a minor bump → 1.1.0.

Open in Web Open in Cursor 

- 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
@adamhenson
adamhenson marked this pull request as ready for review July 24, 2026 21:12
@cursor

cursor Bot commented Jul 24, 2026

Copy link
Copy Markdown

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.

@adamhenson
adamhenson merged commit 1e434e9 into main Jul 24, 2026
4 checks passed

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment on lines +478 to +493
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.`,
},
},
],
};
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing error handlinghandleListRecentSessions 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)}` },
      }],
    };
  }
},

Comment on lines +502 to +517
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.`,
},
},
],
};
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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