feat: add text_completion, generate_embeddings and create_response tools#8
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_completionRaw text/code completion via
/v1/completions. Simpler and faster thanchat_completionfor single-turn tasks like code continuation — no chat formatting overhead.generate_embeddingsGenerate vector embeddings via
/v1/embeddings. Supports single text or batch input. Foundation for RAG and semantic search workflows.create_responseStateful conversations via
/v1/responses. Maintains context automatically viaprevious_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:
except— model auto-detection failure returns a clear JSON error asking the user to specify a model explicitly"qwen/qwen3-coder-30b"fallback entirelygenerate_embeddingsvalidates the response is parseable before returning it"lmstudio-bridge", no breaking change for existing usersLMSTUDIO_PORTis validated as an integer in range 1–65535chat_completionnow also hastimeout=60lmstudio_bridge.pyis changed