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

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

Aberta
#1,648 3 comentários 0 reações 0 responsáveis Ver no GitHub
bug
Linguagem predominante
Python
Estrelas
15.9k
Forks
1.4k
Merge médio
1d 17h
PRs com merge (30d)
163

Descrição

### 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_

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.