Skip to content

fix: preserve datasource response files - #159

Merged
wbxl2000 merged 3 commits into
mainfrom
qer/fix-datasource-response-files
May 28, 2026
Merged

fix: preserve datasource response files#159
wbxl2000 merged 3 commits into
mainfrom
qer/fix-datasource-response-files

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue; fixes a datasource plugin bug found from a failing finance/data-source session.

Problem

Datasource gateway responses can include model-facing content in result.assistant while result.user only contains a short preview. Some APIs also return full CSV data through response.files. The official JS MCP server only read result.user and did not write response.files, so models could see {"data_preview": null} for searches and later fail to read CSV paths that should have been created.

What changed

  • Prefer assistant result text before falling back to user text.
  • Write returned text and base64 files from datasource responses before returning tool output.
  • Added an MCP stdio regression test that exercises the official plugin entrypoint against a mock datasource gateway.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented May 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d1c135d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented May 28, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@e826154
npx https://pkg.pr.new/@moonshot-ai/kimi-code@e826154

commit: e826154

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b6f2c48c1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +216 to +220
await mkdir(path.dirname(name), { recursive: true });
if (file.encoding === 'base64') {
await writeFile(name, Buffer.from(String(file.content), 'base64'));
} else {
await writeFile(name, String(file.content), 'utf8');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict datasource file writes to safe output paths

When the datasource API response includes a files entry whose name is an absolute or parent-traversing path, this server now creates parent directories and overwrites that path directly. In the inspected MCP flow, these writes happen inside the plugin process without going through Kimi Code's normal file-write approval, so a compromised/misconfigured datasource endpoint or KIMI_DATASOURCE_API_URL can overwrite arbitrary user files rather than only the requested CSV/output location. Please validate returned paths against the request's expected file_path/safe temp directory before calling writeFile.

Useful? React with 👍 / 👎.

@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wbxl2000
wbxl2000 merged commit c88b7bf into main May 28, 2026
6 checks passed
@wbxl2000
wbxl2000 deleted the qer/fix-datasource-response-files branch May 28, 2026 11:30
@github-actions github-actions Bot mentioned this pull request May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant