The direct answer

Treat every MCP resource URI as an untrusted request to read a specific customer-owned object—not as a harmless label. The server should first authenticate the caller, derive the tenant from trusted request context, validate the URI against a narrow allowlist, enforce access to the named resource, and only then read or return its contents.

For an indie developer, this distinction matters commercially. A resource server that works for one customer but leaks another customer’s document can turn a small integration into a customer-support incident, a churn event, or a security liability. The goal is not to make agents less capable. It is to make the permitted capability precise enough that an agent can work without gaining ambient access to everything behind the server.

MCP resources are application-driven: the host decides when and how resource context is included. The server still owns the security boundary. The MCP resource specification says servers must validate resource URIs, and access controls should protect sensitive resources. The authorization model can provide the caller’s identity and scopes, but transport-level authentication is not a substitute for checking whether a particular tenant may read a particular resource.

What you are actually securing

MCP resources let a server expose context such as files, database records, schemas, or application-specific data. Each resource has a unique URI. A client can list resources, read them, use URI templates for parameterized resources, and optionally subscribe to changes.

That convenience creates a simple but dangerous implementation pattern:

resource URI -> extract ID -> fetch object -> return content

The vulnerable version skips the questions that matter:

  • Does this URI belong to a supported resource type?
  • Is every segment valid and canonical?
  • Which tenant owns the requested object?
  • Does the caller’s token permit this resource and operation?
  • Could the identifier cause a filesystem, URL, database, or object-storage lookup outside the intended boundary?
  • Should listing and reading produce the same access decision?

A secure design makes those decisions before touching protected data. The same policy should apply to resources/list, resources/read, template expansion, and any subscription or notification flow.

A layered access-control model

Use separate checks for separate mistakes. Authentication answers “who is calling?” Authorization answers “what may they do?” Tenant isolation answers “whose data may they touch?” Resource validation answers “is this URI safe to interpret?”

A practical request pipeline is:

request
  -> authenticate
  -> derive trusted tenant and subject
  -> parse and validate resource URI
  -> resolve within the tenant boundary
  -> authorize the specific read
  -> read and return

Do not let the URI itself declare the tenant. A URI such as mcp://app/resource/tenant-a/report-42 may be useful for display, but the server must not conclude that the request belongs to tenant A merely because the client put that value in the URI. If tenant identity can be supplied or influenced by the caller, it belongs to the prompt-injection and confused-deputy category.

Derive tenant identity from server-controlled context, such as the authenticated token subject, a validated API key, or the local process identity for a stdio deployment. Then compare that tenant with the tenant recorded by the underlying resource. A mismatch must fail closed.

For customer-facing HTTP servers, MCP’s authorization guidance treats the server as an OAuth resource server that accepts access tokens on behalf of resource owners. For local stdio servers, the usual pattern is to retrieve credentials from the environment rather than implementing MCP’s HTTP authorization flow. In either transport, the principle is the same: credentials establish identity; your application enforces resource-level permissions.

1. Scope the URI scheme

Do not accept arbitrary schemes and paths simply because MCP permits custom URI schemes. Choose a scheme that reflects your product’s resource model and bind it to one interpretation.

For example:

mcp://workspace/document/<document-id>
mcp://workspace/project/<project-id>/summary

Then define exactly which resource types are valid. A request for an unsupported type should be rejected before the server attempts to discover or load it.

This is better than exposing a generic URI that might map to any internal service:

mcp://workspace/fetch?target=<arbitrary URL>

That design turns a resource read into a generic network fetch. Even if fetching is your product feature, give it a separate tool or operation with explicit rules, size limits, destination controls, and audit logging. A resource URI should identify data that your server already knows how to classify.

A good URI contract answers four questions:

  1. Which resource types can appear?
  2. Which URI components are identifiers?
  3. What are the limits on identifier length and character set?
  4. How is the URI matched against a stored resource?

2. Validate identifiers, not just the whole URI

A URI can be syntactically valid and still be unsafe. Validation should happen in layers.

Start with the scheme and host. Use an exact match for your custom scheme and reject unexpected hosts or variants. Then parse the path into a fixed number of expected segments. Do not search for the first slash or take everything after a prefix without checking the whole structure.

For each identifier, define an allowlist. Depending on your storage system, that might mean an opaque UUID, a restricted document key, or a conservative character set. Reject values containing:

  • / or \ inside an identifier;
  • . or .. path segments;
  • null bytes and control characters;
  • encoded separators or traversal sequences;
  • unexpected percent encodings;
  • whitespace where the canonical format does not permit it;
  • identifiers beyond your maximum length.

Do not depend on a single denylist. Newline tricks, alternate encodings, and platform-specific path rules make denylists brittle. Parse the URI, constrain the structure, and compare each identifier with a known format.

Then map the validated identifier to a stored object. The safest mapping uses the tenant and identifier together:

lookup(tenant_id, resource_type, resource_id)

not:

lookup(resource_id)

The second form may look correct in a single-tenant demo and fail in production.

3. Prevent path traversal at every filesystem boundary

Path traversal matters when a URI segment eventually becomes a filename or directory. The danger is not limited to literal ../. Encoded separators, mixed path conventions, and absolute paths can also escape an intended directory.

A robust filesystem flow looks like this:

1. Parse the URI.
2. Validate the resource type and identifier.
3. Construct the candidate path with a storage API.
4. Resolve it to an absolute canonical path.
5. Verify it remains inside the configured root.
6. Open with an API that does not reinterpret embedded path segments.
7. Verify the resolved object is the expected regular file.

The root check must happen after canonicalization, not only before joining strings. For example:

/var/data
/var/data/../secrets

A naïve prefix check can also be wrong because /var/data-private shares a textual prefix with /var/data. Compare resolved path components, or use an abstraction that keeps object IDs separate from paths.

A safer option for a small server is to avoid constructing paths from client input at all. Store each resource in a database and keep the filesystem location as a server-controlled field. If you must use paths, use opaque generated names and do not preserve user-supplied slashes.

Do not rely on canonicalization alone as authorization. A canonical path can prove where a file ended up; it does not prove the caller may read it. Tenant and policy checks still come first.

4. Enforce tenant isolation on every access path

Tenant isolation is stronger than filtering a resource list. A resource may remain invisible in resources/list but still be readable if its URI is guessed or copied. Therefore, apply authorization again in resources/read.

A useful invariant is:

A caller may read a resource only if the server derives the same tenant from trusted context and from the stored resource, and the caller’s permissions allow that resource type and action.

Keep tenant filters in the data-access layer where practical. A query shaped like this is safer than fetching first and filtering in application code:

SELECT content FROM resources
WHERE tenant_id = :trusted_tenant
  AND resource_id = :validated_id
  AND resource_type = :validated_type

This reduces the chance that a future code path forgets to check ownership. It also makes the boundary easier to test and review.

For subscriptions, decide whether they can become an indirect leakage channel. If resources/subscribe is supported, authorize the specific URI and make sure notifications are sent only to an authorized session. If notification delivery is difficult to bind safely to the original authorization context, omit the feature until you can enforce it reliably. MCP allows the subscription capability to be omitted.

The resource specification also allows the result of resources/list to vary according to the authorization presented on the request. That is useful, but filtering the list is a usability feature, not the security boundary. Direct reads still require authorization.

5. Separate “not visible” from “not allowed” carefully

You want failures that do not disclose sensitive existence. Avoid returning different errors for a resource that exists in another tenant and one that does not exist at all, unless your threat model and product requirements justify that distinction. A generic resource-not-found response can reduce information leakage.

The MCP resource documentation identifies -32002 for resource-not-found and -32603 for internal errors. Use a standard JSON-RPC error for ordinary client mistakes, and avoid exposing filesystem paths, database details, stack traces, or tenant identifiers in the response.

There is a trade-off here. A developer debugging a local server benefits from specific errors; a public server benefits from generic responses. A useful compromise is detailed logs for operators and sanitized client errors. Record enough context to investigate an access denial without logging secrets or complete sensitive resource contents.

6. Make authorization decisions resource-specific

A coarse scope such as resources:read can authorize every resource operation on the server. That may be acceptable for a low-risk, single-user local server. It is usually too broad for a multi-tenant product.

Define resource classes according to actual business sensitivity. A possible set might include public metadata, workspace documents, customer records, billing records, and internal operational logs. Give each class a narrowly named permission and, where useful, an explicit tenant condition.

The authorization model should combine:

  • capability: may the caller read resources at all?
  • resource type: may the caller read this class of resource?
  • tenant: may the caller access this customer’s resources?
  • instance policy: may this particular resource be shared or restricted?
  • action: read, list, subscribe, or update, if the server supports more than reading.

This model scales better than adding special-case checks to individual handlers. It also gives audit logs a useful decision vocabulary.

If you are choosing the wider token and scope strategy, see How to Choose an MCP Server Authorization Model Without Handing Agents Too Much Access. The resource design still needs to enforce the scopes you choose.

A compact validation example

The following pseudocode shows the order of operations without tying the guide to a particular language or SDK:

async function readResource(uriText, authContext) {
  const principal = authenticate(authContext);
  const tenantId = principal.tenantId; // trusted, server-derived

  const uri = parseResourceUri(uriText);
  assertEqual(uri.scheme, "mcp");
  assertEqual(uri.authority, "workspace");
  assertEqual(uri.pathSegments.length, 2);

  const resourceType = uri.pathSegments[0];
  const resourceId = uri.pathSegments[1];

  assertAllowedType(resourceType);
  assertValidIdentifier(resourceId);

  const resource = await store.find({
    tenantId,
    type: resourceType,
    id: resourceId,
  });

  if (!resource) {
    throw resourceNotFound();
  }

  assertCanRead(principal, resource.type, resource.id);
  return loadApprovedContents(resource);
}

Notice what is absent: the server never uses a tenant supplied inside the URI, never splits a path by searching for delimiters, and never fetches the object before checking authorization.

For a filesystem-backed resource, loadApprovedContents should perform the canonical-root check again as a defense in depth. The store lookup and the filesystem read may be separate boundaries.

7. Test the denials, not only the happy path

A successful read by an authorized user proves very little. The important release tests are the requests that should fail.

Build a matrix for every supported resource type:

Test Expected result
Valid URI, authorized tenant and resource Resource returned
Valid identifier from another tenant Not found or denied; no content
Missing or invalid credential Unauthorized
Token lacks the required resource scope Forbidden
Unknown resource type Invalid request
Extra or missing path segment Invalid request
Identifier containing .. Invalid request
Identifier containing encoded separators Invalid request
Absolute path disguised as an identifier Invalid request
Resource listed for tenant A, then read as tenant B Denied
Subscription to an inaccessible resource Denied
Resource removed after listing Not found at read time

Also test behavior after a permission change or token revocation. A cached authorization decision must not outlive the policy that allowed it without a clear, bounded expiration strategy.

For local stdio servers, add tests for environment boundaries: which directories the process can access, which credentials are present, and whether the server starts with a restricted working directory. For HTTP servers, test whether tenant identity can be altered through headers, query parameters, request bodies, or client-supplied resource metadata. The server should ignore all of these for tenant selection unless they are part of a validated, trusted authorization claim.

8. Add an audit trail before customers ask for one

You do not need a large security platform to start. You need enough evidence to answer: who attempted to read which resource, under which tenant, when, and what policy decision occurred.

Useful fields include:

  • a request or trace identifier;
  • authenticated subject and client identifier;
  • trusted tenant identifier;
  • normalized resource type;
  • a hashed or safely recorded resource identifier;
  • operation, such as list, read, or subscribe;
  • decision, such as allowed, denied, or not found;
  • reason code;
  • timestamp.

Avoid recording bearer tokens, raw sensitive content, or complete client-supplied URIs when those fields contain secrets or personal data. Alert on patterns such as repeated cross-tenant attempts, bursts of invalid identifiers, or many denied subscription requests. An isolated typo should not become an incident; a systematic probing pattern deserves attention.

A pre-launch checklist

Before publishing a resource-enabled MCP server, verify that you can answer “yes” to each question:

  • Does every request have a server-trusted tenant identity?
  • Is authentication separate from resource authorization?
  • Are resource types and URI components explicitly allowlisted?
  • Are identifiers parsed and validated before lookup?
  • Does the data query include the trusted tenant constraint?
  • Does resources/read repeat authorization even when the resource was previously listed?
  • Are filesystem paths canonicalized and confined to an approved root?
  • Are arbitrary URLs and generic fetches excluded from resource URIs?
  • Are subscriptions protected and tied to an authorized context?
  • Do errors avoid exposing internal paths or tenant information?
  • Do audit logs capture decisions without storing secrets?
  • Have you tested cross-tenant reads, traversal variants, malformed URIs, and revoked permissions?
  • Is the resource capability advertised only after those controls work?

If the answer is no, do not advertise resources, listChanged, or subscribe merely because the client SDK supports them. A smaller, correctly secured resource surface is more valuable than a broad one that creates avoidable incident risk.

Common design mistakes

“The client will only send valid URIs”

Clients can be buggy, compromised, operated by different teams, or manipulated by agent-generated content. The server must validate.

“The token already proves authorization”

Authentication and broad scopes do not prove that a caller may read a particular object. Resource-level and tenant-level checks remain necessary.

“Filtering the list is enough”

Guessed identifiers and copied URIs bypass list filtering. Protect the read operation itself.

“We sanitize with replace('../', '')”

That is not a complete path-traversal defense. Use structured parsing, identifier allowlists, canonical containment checks, and safe storage APIs.

“The agent will respect the tenant label”

The agent is part of a probabilistic workflow. Tenant enforcement belongs in deterministic server code.

Frequently asked questions

Should a local, single-user MCP server use the same controls?

The threat and scale are smaller, but the core invariants still matter. A local server may use environment-provided credentials and filesystem permissions instead of OAuth. It should still constrain resource types, avoid unsafe path construction, and fail when an expected resource boundary is missing. If the server can read the user’s whole home directory, the resource API may be more powerful than its advertised purpose requires.

Is it safe to expose signed URLs as MCP resources?

A signed URL may grant access to a specific object for a limited time, but it does not replace server-side policy. Decide who can obtain the URL, ensure it is scoped to one resource and operation, avoid logging it, and understand whether the client can share it. If revocation or tenant checks matter, keep the authoritative read on the server and return content or a tightly scoped result instead.

Can URI templates be used safely?\n

Yes, but template expansion is not validation. Validate each expanded argument with the same rules as a literal URI. Keep the number of arguments fixed, restrict each argument to a known identifier format, and ensure expansion cannot introduce path segments or alter the resource type.

How do I balance convenience with isolation?\n

Expose a small set of product-level resources that correspond to clear workflows—such as a document, a project summary, or a customer record—rather than a generic filesystem. A narrower surface takes more design work, but it reduces the number of special cases, makes policy auditable, and gives customers an agent they can understand.

The founder’s decision

If you are deciding whether to ship resources now, ship only when you can state the tenant boundary, resource classes, identifier rules, and denial behavior in plain language. If those answers are unclear, use tools for a narrow workflow or expose an approved summary until the resource model is safer.

The practical commercial goal is simple: let agents retrieve exactly the context needed to complete customer work without giving them a backstage key to the entire product. That design is not only a security control. It is also what makes an MCP integration easier to trust, explain, support, and sell.

Sources