Start an MCP stdio server.
(
content: Sequence[ContentType] = (ContentType.CODE,),
)
| 136 | |
| 137 | |
| 138 | async def serve( |
| 139 | content: Sequence[ContentType] = (ContentType.CODE,), |
| 140 | ) -> None: |
| 141 | """Start an MCP stdio server.""" |
| 142 | cache = _IndexCache(content=content) |
| 143 | |
| 144 | async def _load_and_prewarm() -> None: |
| 145 | """Pre-load the embedding model in parallel with starting the server.""" |
| 146 | try: |
| 147 | _, cache._model_path = await asyncio.to_thread(load_model) |
| 148 | except Exception as exc: |
| 149 | logger.exception("Failed to load embedding model") |
| 150 | cache._model_error = exc |
| 151 | return |
| 152 | finally: |
| 153 | cache._model_ready.set() |
| 154 | |
| 155 | init_task = asyncio.create_task(_load_and_prewarm()) |
| 156 | server = create_server(cache) |
| 157 | try: |
| 158 | await server.run_stdio_async() |
| 159 | finally: |
| 160 | if not init_task.done(): |
| 161 | init_task.cancel() |
| 162 | |
| 163 | |
| 164 | class _IndexCache: |