Open
Description
Question
mcp = FastMCP("completion1",
instructions="A server that generates code from user prompts and JSON context. For all validation code generation requests from developers")
# Global store for extracted values
repo_cache = []
@mcp.tool()
async def long_task(files: list[str], ctx: Context) -> str:
"""Process a list of files asynchronously.
Args:
files (list[str]): _description_
ctx (Context): _description_
Returns:
str: _description_
"""
global repo_cache
repo_cache.clear() # reset
for i, file in enumerate(files):
ctx.info(f"Processing {file}")
with open(file, "r", encoding="utf-8") as f:
data = f.read()
# Just for illustration: suppose lines in file are repo names
lines = data.splitlines()
repo_cache.extend(lines)
await ctx.report_progress(i + 1, len(files))
ctx.info(f"Cached repos: {repo_cache}")
return "Processing complete"
@mcp.completion()
async def free_text_completion(argument: CompletionArgument) -> Completion:
"""Handle free text completion requests.
Args:
argument (CompletionArgument): The argument containing the user's input.
Returns:
Completion: A completion object containing suggestions based on the user's input.
"""
# Use the global repo_cache to provide suggestions
global repo_cache
suggestions = repo_cache or ["code_genrator", "some_other_repo"]
matches = [r for r in suggestions if r.startswith(argument.value)]
return Completion(values=matches)
if __name__ == "__main__":
mcp.run(transport="stdio")
we have three queries as follows-
I have implemented a context loader & a completion endpoint as above I'm using mcp tools & it's completion endpoint with GitHub copilot in VS code.
Hear are my queries-
- How can I get my recommendation using completion endpoint in completion1.
- Where I will be getting the recommendation in VS code file editor or in GitHub copilot while MCP is connected & is running.
- What are the additional implementations I can add here to make the MCP'c workflow better.
My mcp for now is loading the context & further generation are happening through it one I have sent a query from GitHub copilot.
Please help with the queries I have written above.