fix: render resource content blocks consistently (#124) (thanks @mvanhorn)

This commit is contained in:
Peter Steinberger 2026-03-28 19:25:34 +00:00
parent 2bd30c235c
commit e7c6bef1a2
3 changed files with 22 additions and 0 deletions

View File

@ -3,6 +3,7 @@
## [Unreleased]
### CLI
- Render `resource` content blocks in call output helpers instead of dropping them, including markdown resources and JSON text payloads. (PR #124, thanks @mvanhorn)
- Preserve default imports when `mcporter config add` writes a config file, instead of forcing `"imports": []`.
- OAuth: avoid crashing on headless Linux when `xdg-open` is unavailable; clear stale dynamic-port client registrations; close callback server if stale-client persistence reads fail. (PR #72, thanks @mgonto)
- Added optional `oauthScope`/`oauth_scope` config override as an escape hatch for providers that require explicit scopes.

View File

@ -120,8 +120,12 @@ function collectCallContent(raw: unknown): CollectedCallContent {
const resource = typedEntry.resource as Record<string, unknown> | undefined;
if (resource && typeof resource === 'object') {
const uri = typeof resource.uri === 'string' ? resource.uri : '';
const mimeType = typeof resource.mimeType === 'string' ? resource.mimeType : '';
if (typeof resource.text === 'string') {
textEntries.push(resource.text);
if (mimeType.toLowerCase().includes('markdown')) {
markdownEntries.push(resource.text);
}
const parsed = tryParseJson(resource.text);
if (parsed !== null) {
jsonCandidates.push(parsed);

View File

@ -235,6 +235,23 @@ describe('createCallResult resource extraction', () => {
expect(result.text()).toBe('# My Project\n\nA description.');
});
it('treats markdown resources as markdown output too', () => {
const response = {
content: [
{
type: 'resource',
resource: {
uri: 'file:///repo/README.md',
mimeType: 'text/markdown',
text: '# My Project\n\nA description.',
},
},
],
};
const result = createCallResult(response);
expect(result.markdown()).toBe('# My Project\n\nA description.');
});
it('creates placeholder for binary resource content blocks', () => {
const response = {
content: [