Skip to content

feat: add text_completion, generate_embeddings and create_response tools#8

Merged
infinitimeless merged 1 commit into
mainfrom
feat/text-completion-embeddings-stateful
Apr 10, 2026
Merged

feat: add text_completion, generate_embeddings and create_response tools#8
infinitimeless merged 1 commit into
mainfrom
feat/text-completion-embeddings-stateful

Conversation

@infinitimeless
Copy link
Copy Markdown
Owner

Summary

Adds three new MCP tools to the bridge, bringing the total from 4 to 7.

Credit

These tools were originally proposed and implemented by @ahmedibrahim085 in PR #5. That PR was closed after a long delay on our side, during which Ahmed went on to build the excellent lmstudio-bridge-enhanced. This implementation is a clean re-write inspired by his work, with the issues identified during code review addressed.

New Tools

text_completion

Raw text/code completion via /v1/completions. Simpler and faster than chat_completion for single-turn tasks like code continuation — no chat formatting overhead.

generate_embeddings

Generate vector embeddings via /v1/embeddings. Supports single text or batch input. Foundation for RAG and semantic search workflows.

create_response

Stateful conversations via /v1/responses. Maintains context automatically via previous_response_id — no manual message history management needed. Requires LM Studio v0.3.29+.

Changes vs PR #5

All issues identified in the code review have been addressed:

  • No bare except — model auto-detection failure returns a clear JSON error asking the user to specify a model explicitly
  • No hardcoded model name — removed the "qwen/qwen3-coder-30b" fallback entirely
  • Malformed JSON guardgenerate_embeddings validates the response is parseable before returning it
  • Server name unchanged — still "lmstudio-bridge", no breaking change for existing users
  • Port validationLMSTUDIO_PORT is validated as an integer in range 1–65535
  • Timeout on all requestschat_completion now also has timeout=60
  • No extraneous files — only lmstudio_bridge.py is changed

Three new MCP tools inspired by @ahmedibrahim085's contribution in PR #5.
Implemented cleanly with all code review issues addressed:
- No bare except clauses
- No hardcoded model fallback names
- Malformed JSON handled in generate_embeddings
- Server name unchanged (lmstudio-bridge)
- Port validation added
- timeout added to all requests

Credit: original concept by @ahmedibrahim085
@infinitimeless infinitimeless merged commit bc1e794 into main Apr 10, 2026
1 check passed
@infinitimeless infinitimeless deleted the feat/text-completion-embeddings-stateful branch April 10, 2026 19:56
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