Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This Software contains code from the following open source projects:
| :--------------- | :---------------- | :----------- | :--------------------------------------------------- |
| [@ast-grep/napi](https://www.npmjs.com/package/@ast-grep/napi) | 0.37.0 | MIT | https://ast-grep.github.io |
| [@clack/prompts](https://www.npmjs.com/package/@clack/prompts) | 1.0.1 | MIT | https://github.com/bombshell-dev/clack/tree/main/packages/prompts#readme |
| [@modelcontextprotocol/node](https://www.npmjs.com/package/@modelcontextprotocol/node) | 2.1.2 | Apache-2.0 | https://modelcontextprotocol.io |
| [@modelcontextprotocol/server](https://www.npmjs.com/package/@modelcontextprotocol/server) | 2.4.0 | Apache-2.0 | https://modelcontextprotocol.io |
| [@opentelemetry/api](https://www.npmjs.com/package/@opentelemetry/api) | 1.9.0 | Apache-2.0 | https://github.com/open-telemetry/opentelemetry-js/tree/main/api |
| [@opentelemetry/api-logs](https://www.npmjs.com/package/@opentelemetry/api-logs) | 0.223.0 | Apache-2.0 | https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/api-logs |
| [@opentelemetry/auto-instrumentations-node](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node) | 0.81.2 | Apache-2.0 | https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/auto-instrumentations-node#readme |
Expand Down
18 changes: 18 additions & 0 deletions docs/docs/api/appkit/Function.mcp.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/docs/api/appkit/Interface.BasePluginConfig.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions docs/docs/api/appkit/Interface.FunctionTool.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 108 additions & 0 deletions docs/docs/api/appkit/Interface.McpPluginConfig.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions docs/docs/api/appkit/Interface.ToolConfig.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions docs/docs/api/appkit/Interface.ToolkitOptions.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/docs/api/appkit/index.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions docs/docs/api/appkit/typedoc-sidebar.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions docs/docs/plugins/mcp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
sidebar_position: 18
---

# MCP server plugin

<!-- AUTO-GENERATED: stability-banner-start -->
:::warning Beta plugin
This plugin is currently **beta**. APIs may change between minor releases. Import from `@databricks/appkit/beta`. See [Plugin Stability Tiers](./stability.md).
:::
<!-- AUTO-GENERATED: stability-banner-end -->

The beta MCP plugin serves selected AppKit tools on `/mcp` using stateless
streamable HTTP. Register the App as a Unity Catalog MCP Service behind Unity
Gateway.

:::danger Governance
Calls made directly to `/mcp` skip Unity Gateway's governance until blocking
direct calls exists. Restrict access to the App accordingly.
:::

## Setup

```ts
import { createApp, genie, server } from "@databricks/appkit";
import { mcp, tool } from "@databricks/appkit/beta";
import { z } from "zod";

await createApp({
plugins: [
server(),
genie({ spaces: { sales: "space-id" } }),
mcp({
name: "sales",
description: "Sales tools",
allowedOrigins: ["https://portal.example.com"],
tools(plugins) {
return {
...plugins.genie.toolkit({ only: ["sales.sendMessage"] }),
lookupCustomer: tool({
description: "Look up a customer by ID",
schema: z.object({ id: z.string() }),
runAs: "user",
scopes: ["sql"],
annotations: { effect: "read" },
execute: async ({ id }) => ({ id }),
}),
};
},
}),
],
});
```

The object returned by `tools(plugins)` is exactly the set served. Toolkit
entries retain their names (for example `genie.sales.sendMessage`); developer
tools use the object key. Toolkit options `only`, `except`, `prefix` and
`rename` work as they do for agents. Toolkit entries are read-only by default:
write, update, destructive, and tools without an `effect` are omitted unless
named explicitly in `only`. Developer tools are included explicitly by key.

## Identity and scopes

`runAs: "user"` is the default and uses the caller's forwarded token.
`runAs: "app"` executes as the App's service principal. Set it on `tool()` or
on `toolkit()`; the caller cannot choose it. App-run tools are logged with a
warning. `runAs` and `scopes` are honoured by `mcp()` only: agents sharing
these tools continue to use their own identity.

For user-run developer tools, supply `scopes: ["sql", ...]`. User-run toolkit
scopes come from the plugin manifest and resource types. At startup AppKit logs
each tool's identity and scopes and the union to declare in the App's
`user_api_scopes`. When running in a Databricks App it also warns if the App's
effective scopes are missing any of them. A lookup failure only warns.

Lakebase toolkit tools run as the App and add no user scopes. Explicit
`runAs: "user"` is refused at startup: no workspace test has yet confirmed
that an Apps-forwarded user token can mint a Lakebase credential, and AppKit
does not map the postgres scope. This stopgap does not affect developer tools
that query Lakebase themselves.

## Annotations

| AppKit effect | `readOnlyHint` | `destructiveHint` |
|---|---|---|
| `read` | `true` | omitted |
| `write` / `update` | `false` | `false` |
| `destructive` | `false` | `true` |

Legacy `readOnly` and `destructive` flags map to their corresponding hints;
`idempotent` maps to `idempotentHint`.

## HTTP behavior and errors

POST supports MCP. GET and DELETE return 405. Requests without Origin are
accepted; requests with a valid same-origin host or a listed `allowedOrigins`
origin are accepted. Other, malformed, or `null` origins return 403.

Tool failures return MCP `isError` content. Missing user tokens and recognizable
missing-scope errors identify the required `user_api_scopes`; other failures
return a fixed message and log the details. Before MCP runs, errors return
JSON-RPC error objects with the HTTP status preserved: malformed JSON is
`-32700`, 413 and other 4xx are `-32600`, 401 is `-32000`, and 5xx is
`-32603` with a fixed internal-error message.

In development, AppKit's usual missing-token fallback runs a user tool as the
service principal with a warning.
2 changes: 2 additions & 0 deletions packages/appkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
"@databricks/sdk-scim": "0.51.0",
"@databricks/sdk-statementexecution": "0.52.0",
"@databricks/sdk-warehouses": "0.53.0",
"@modelcontextprotocol/node": "2.1.2",
"@modelcontextprotocol/server": "2.4.0",
"@opentelemetry/api": "1.9.0",
"@opentelemetry/api-logs": "0.223.0",
"@opentelemetry/auto-instrumentations-node": "0.81.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/appkit/src/beta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@ export {
type PolicyDecision,
type PolicyDenial,
} from "./plugins/database/operations";

export type { McpPluginConfig } from "./plugins/mcp";
6 changes: 6 additions & 0 deletions packages/appkit/src/core/agent/scope-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** Extract the scope list from the Databricks API's missing-scope error. */
export function getRequiredScopes(error: unknown): string | undefined {
const message = error instanceof Error ? error.message : String(error);
const match = message.match(/required scopes?:\s*([^[\]]+)/i);
return match?.[1].trim().replace(/\s+/g, " ");
}
4 changes: 4 additions & 0 deletions packages/appkit/src/core/agent/tools/function-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export interface FunctionTool {
* tool indexes.
*/
annotations?: ToolAnnotations;
/** Honoured by mcp() only; agents use their own identity. */
runAs?: "user" | "app";
/** Honoured by mcp() only. */
scopes?: string[];
/**
* Returns any shape; downstream `normalizeToolResult` serializes to a
* string before handing the value to the LLM.
Expand Down
Loading
Loading