Skip to content

Cedar policies for MCP tools in aiwcorpo MCP Gateway

aiwcorpo MCP Gateway decides every tool call with Cedar. Two Cedar rules matter for everything below: with no matching permit the answer is deny, and a matching forbid beats any permit. The platform adds a third rule of its own: a server may bring policies for its resources, but nothing it brings decides whether a tool may be called at all.

This guide explains the model and shows policies that pass the platform’s validation. The portal steps are in Add and approve an MCP server, Grant access and Overrides.

The Cedar model is contract C7 in mcp-contracts 7.2.0, file cedar/mcp.cedarschema. It names no system and no server. The core of it:

entity ResourceScope;
entity UserGroup in [ResourceScope];
entity User in [UserGroup] {
username: String,
client: String,
mfaAge?: Long,
scopes: Set<ResourceScope>,
};
entity Tool {
server: String,
name: String,
risk: String,
requiredGroup: UserGroup,
additionalGroup?: UserGroup,
};
type RequestContext = {
client: String,
mfaAge?: Long,
credentialType?: String,
refs?: Set<ResourceScope>,
};
action "call" appliesTo {
principal: [User],
resource: [Tool],
context: RequestContext,
};

How the entities are filled:

  • User::"<sub>" is the user from the identity provider token. Its parents are the user’s groups that start with mcp-, each a UserGroup. A group’s parents are the ResourceScope entities the scope mapping grants it, so principal in ResourceScope::"Jira::Project/ABC" holds for a member of a mapped group.
  • User.scopes is one flat set of every scope the user’s groups are mapped to.
  • Tool::"<system>__<tool>" is an approved tool. risk is READ_ONLY, UPDATE or DESTRUCTIVE, and requiredGroup follows from it: mcp-<system>-read, -write or -destructive. This is the only place where a group name is derived.
  • context.client is the azp of the token. context.refs holds the scope ids of tool arguments whose resource type is declared with earlyScopeCheck, for example Jira::Project/ABC for a project key.

The Java library pl.aiwcorpo.mcp:mcp-cedar-entities:7.2.0 builds these entities, and both the gateway and the servers use it, so they evaluate the same data.

Gateway Server
Question May this user call this tool? May this user act on this resource?
Action Action::"call" <Namespace>::Action::"read", "update", "delete" or "admin"
Resource Tool An entity of the server’s namespace, resolved from the product with the user’s credential
Policies Platform policies plus overrides with the target Gateway The server’s own policies, policies the platform generates for it, and overrides with the target All servers or One server

The gateway decides first. If it allows the call, the server resolves each resource the tool names and decides again on the real object: the project as Jira returns it, not the key the agent typed.

The gateway evaluates call only with the four policies in cedar/platform/ and the administrator’s overrides. The only permit is:

@id("platform-call-by-group")
permit (principal, action == Action::"call", resource is Tool)
when { principal in resource.requiredGroup };

The three forbid policies narrow it: platform-call-additional-group (a tool that names an extra group in its manifest also needs that group), platform-call-write-outside-scope (a write whose context.refs is not inside principal.scopes) and platform-call-write-without-refs (a write without refs is refused rather than treated as having nothing to check).

The AI client is checked in code before Cedar: an azp that is not in MCP_ALLOWED_CLIENTS is refused whatever the policies say. Any evaluation error is a deny. The audit records the decision with the policy revision (policyRevision); see Audit.

A server keeps its policies in src/main/resources/mcp/policies/ and publishes them in its manifest (policies with the namespace, the schema and the files, plus policiesHash). The files:

  • schema.cedarschema: exactly one namespace, the server’s own, with an entity type for each resource and the actions read, update, delete and admin. Every entity type has scopes: Set<ResourceScope>.
  • resource-types.json: one declaration per type, with idPattern, optional scopePattern, earlyScopeCheck, the parent and the classification attribute.
  • *.cedar: the access rules, each with an @id unique in the server.

The Jira server, for example, lets members of mcp-jira-write change issues only inside the projects their groups are mapped to:

@id("jira-update-issue-in-scope")
permit (
principal in UserGroup::"mcp-jira-write",
action == Jira::Action::"update",
resource is Jira::Issue
)
when { principal in resource.scopes };

When the gateway registers a server, it composes the base schema with the fragment and validates in strict mode. It refuses the manifest (422 manifest_rejected with policies_invalid or resource_types_invalid) when the fragment declares anything outside its namespace, uses another action, gives an action another principal or context type, lacks scopes on a type, or declares types that differ from resource-types.json. It also refuses a policy that does not parse, has no @id, uses the prefixes platform- or override-, mentions Action::"call" or Tool, or that Cedar reports as impossible (a forbid that never matches would open access silently).

Next to the server’s own policies the platform always loads forbid policies generated from the declarations, so a server cannot leave them out. For the Jira declarations they are:

@id("platform-jira-restricted-project")
forbid (principal, action, resource is Jira::Project)
when { resource.category == "restricted" };
@id("platform-jira-restricted-issue-by-project")
forbid (principal, action, resource is Jira::Issue)
when { resource.project.category == "restricted" };
@id("platform-jira-issue-service-account-outside-scope")
forbid (principal, action, resource is Jira::Issue)
when {
!(context has credentialType && ["user-oauth", "user-secret", "token-exchange"].contains(context.credentialType)) &&
!(principal in resource.scopes)
};

(The fourth, platform-jira-project-service-account-outside-scope, is the same rule for Jira::Project.)

A server cannot approve its own policies. After the first pull, and after every change of a policy or a declaration, the portal shows Policies and resource types waiting for approval under Approvals. Show differences puts the approved and the pending text side by side; Approve policies needs a fresh MFA.

Until the new policiesHash is approved, the tools of the server stay blocked. A running server compares its own hash with the approved one, which the gateway sends in the policy data, and refuses calls with policies_not_approved or policies_differ while they differ. The gateway pushes the policy data (scope mapping, allowed clients, server overrides, approved hash) at least every 60 seconds, with a revision that only grows.

The policies below pass PolicyFragments.validateFragment and PolicyFragments.validateOverride from mcp-cedar-entities 7.2.0, the same checks the gateway runs, against the Jira server’s schema.

A server rule that keeps projects of the category finance for one group. It is a forbid, so it only narrows the read and write permits. The classification value is normalized to lower case ASCII before evaluation.

@id("jira-finance-projects-only-for-finance")
forbid (principal, action, resource is Jira::Project)
when {
resource.category == "finance" &&
!(principal in UserGroup::"mcp-jira-finance")
};
@id("jira-finance-issues-only-for-finance")
forbid (principal, action, resource is Jira::Issue)
when {
resource.project.category == "finance" &&
!(principal in UserGroup::"mcp-jira-finance")
};

An override with the target Gateway that makes claude.ai read only while Claude Code keeps write tools:

@id("override-claude-ai-read-only")
forbid (principal, action == Action::"call", resource is Tool)
when { resource.risk != "READ_ONLY" && context.client == "claude-ai" };

An override with the target One server (mcp-jira) that freezes all work on issues of one project during an incident:

@id("override-freeze-project-abc")
forbid (principal, action, resource is Jira::Issue)
when { resource.project.key == "ABC" };

A policy that reads an attribute the schema does not have is refused when you save it. For example resource.category on a Tool gives attribute category on entity type Tool not found.

Server authors test policies in plain JUnit with PolicyDecisions from mcp-platform-test: an allowed and a denied case for each rule, restricted data and the service account included. See Write a server from the template. The Cedar files, schema and test vectors are in the contracts (Platform contracts).