ag-ui-protocol / ag-ui-protocol/ag-ui

[Bug]: mcp-apps-middleware does not recognize standard `_meta.ui.resourceUri` format

未關閉
#1,648 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bug
主要語言
Python
星號
15.9k
分支
1.4k
平均合併
1 天 17 小時
30 天內合併 PR
163

描述

### Pre-flight Checklist

- [x] I have searched [existing issues](https://github.com/ag-ui-protocol/ag-ui/issues) and this hasn't been reported yet.
- [x] I am using the **latest** version AG-UI.

### Describe the Bug

## Summary

`@ag-ui/mcp-apps-middleware` currently only recognizes the legacy flat metadata key:

```json
"_meta": {
"ui/resourceUri": "ui://plm/search-results"
}
```

It does not recognize the newer MCP Apps standard nested format:

```json
"_meta": {
"ui": {
"resourceUri": "ui://plm/search-results"
}
}
```

## Current implementation

Current middleware logic checks only:

```ts
tool._meta?.["ui/resourceUri"]
```

Example from `middlewares/mcp-apps-middleware/src/index.ts`:

```ts
function hasUIResource(tool) {
return typeof tool._meta?.["ui/resourceUri"] === "string";
}
```

## Impact

If an MCP server emits only the spec-compliant nested format:

```json
"_meta": {
"ui": {
"resourceUri": "ui://..."
}
}
```

then the middleware:

- does not detect the tool as a UI tool
- does not inject it into `input.tools`
- does not handle the MCP App lifecycle
- `ACTIVITY_SNAPSHOT`
- `resources/read`
- `postMessage`

## Expected behavior

Middleware should support both formats for backward compatibility:

```ts
function getUIResourceUri(tool) {
return (
tool?._meta?.ui?.resourceUri ??
tool?._meta?.["ui/resourceUri"]
);
}
```

## Suggested fix

Update all metadata reads in the middleware to support:

- `_meta.ui.resourceUri` (preferred / spec-compliant)
- `_meta["ui/resourceUri"]` (legacy compatibility)

## Additional context

The MCP Apps documentation and newer examples use the nested format:

```json
_meta.ui.resourceUri
```

while the middleware currently assumes the legacy flat slash-key format only.

### Steps to Reproduce

1. Install `@ag-ui/mcp-apps-middleware@0.0.3`.
2. Create or use an MCP server that exposes a UI tool using the standard nested MCP Apps metadata format:

```json
{
"_meta": {
"ui": {
"resourceUri": "ui://plm/search-results"
}
}
}

### Expected Behavior

```markdown
The middleware should detect MCP Apps UI tools that use the standard nested metadata format:

```json
{
"_meta": {
"ui": {
"resourceUri": "ui://plm/search-results"
}
}
}

### Environment

```text
AG-UI package(s) & version(s):
- `@ag-ui/mcp-apps-middleware@0.0.3`

Runtime:
- Node.js
- MCP server emitting nested `_meta.ui.resourceUri`
```

### Screenshots

_No response_

### Logs & Errors

```shell

```

### Additional Context

_No response_

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。