mcp-resource-patterns
Use MCP Resources correctly — the read-only, URI-addressable data primitive — and know when to pick resources, tools, or prompts. Covers templated URIs, subscriptions, and common mistakes. Use this skill when designing MCP servers that expose data, deciding between tool vs resource, or implementing resource subscriptions for live data. Activate when: MCP resource, resource template, resource vs tool, subscribe resource, MCP URI schema.
What this skill does
# MCP Resource Patterns
**Resources are read-only, URI-addressable data. Get them right and your server feels like a filesystem the agent can browse.**
## When to Use
- Deciding whether a read operation should be a tool or a resource
- Exposing hierarchical data (files, tickets, logs) to an agent
- Implementing live-updating data via subscriptions
- Designing URI schemes for a new MCP server
## Tool vs Resource vs Prompt
| Aspect | Tool | Resource | Prompt |
|---|---|---|---|
| Invocation | Agent calls it | Agent reads it | User selects it |
| Side effects | Allowed | No | No |
| Addressing | Name + args | URI | Name |
| Result | Agent-chosen | User/agent-attached | Template expansion |
| Example | `create_issue` | `github://issues/123` | `/summarize-pr` |
**Rule of thumb**: if the agent needs to decide *whether* to read it, it's a tool. If the user or agent needs to *attach* specific known data to context, it's a resource.
## Static Resources
```ts
server.resource(
"changelog",
"file://changelog.md",
async () => ({
contents: [{
uri: "file://changelog.md",
mimeType: "text/markdown",
text: await fs.readFile("CHANGELOG.md", "utf-8"),
}],
}),
);
```
## Templated Resources
Use URI templates (RFC 6570) for addressable collections:
```ts
server.resource(
"issue",
"github://repos/{owner}/{repo}/issues/{number}",
async (uri, { owner, repo, number }) => {
const issue = await gh.issues.get({ owner, repo, issue_number: +number });
return {
contents: [{
uri: uri.href,
mimeType: "application/json",
text: JSON.stringify(issue.data),
}],
};
},
);
```
The client auto-discovers the template and can fetch any matching URI.
## Listing Resources
```ts
server.setRequestHandler(ListResourcesRequestSchema, async () => ({
resources: [
{ uri: "github://repos/acme/api/issues", name: "Open issues", mimeType: "application/json" },
{ uri: "github://repos/acme/api/prs", name: "Open PRs", mimeType: "application/json" },
],
}));
```
Keep the list short — this is what the user sees in the resource picker.
## Subscriptions (Live Data)
For data that changes (logs, metrics, ticket state), support subscriptions so the client re-reads on update:
```ts
server.resource(
"live-log",
"logs://app/{stream}",
{ subscribe: true },
async (uri, { stream }) => ({ contents: [{ uri: uri.href, text: await tail(stream) }] }),
);
// When data changes:
logStream.on("update", (stream) => {
server.sendResourceUpdated({ uri: `logs://app/${stream}` });
});
```
The client listens for `notifications/resources/updated` and re-fetches.
## URI Scheme Design
A good scheme is:
1. **Hierarchical** — `github://repos/{owner}/{repo}/issues/{number}`, not `github://issue?id=123&repo=...`
2. **Guessable** — if the agent knows `github://repos/acme/api/issues/5`, it can guess `.../issues/6`
3. **Unique per server** — prefix with your server's identity (`github://`, not `resource://`)
4. **MIME-tagged** — always include `mimeType` so the client renders correctly
Avoid opaque IDs in URIs when human-readable keys exist — `linear://issues/ENG-42` beats `linear://issues/a3f8c21d`.
## Binary Resources
```ts
return {
contents: [{
uri: uri.href,
mimeType: "image/png",
blob: base64Encode(pngBytes),
}],
};
```
Clients that support vision models will attach PNGs directly. Text-only clients will skip binary resources.
## Pagination
MCP has no native pagination. Two conventions:
1. **Sub-resources**: `github://issues?page=2` as a distinct URI
2. **Cursor in body**: return JSON with `nextPageUri` and let the agent fetch it
Prefer (1) — clients cache per-URI.
## Common Mistakes
1. **Using tools for reads** — `get_issue` should be `github://issues/{number}` so the user can attach it as context
2. **Using resources for actions** — a resource read must not mutate state, ever
3. **No `mimeType`** — breaks rich clients and model understanding
4. **Templates with too many variables** — 5+ vars means you probably need a search tool instead
5. **Unstable URIs** — if `github://issues/123` points to different data tomorrow, caching breaks
## Best Practices
1. Design URIs as if they'll be bookmarked — stable, human-readable, hierarchical
2. Expose bulk endpoints as resource listings, detail endpoints as templated resources
3. Keep resource lists small (< 50 items); let templates handle the long tail
4. Use subscriptions sparingly — each one holds a connection open
5. Document your URI scheme in the server README — users browse before they call
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.