Configure TypeScript and Python language servers in Serena container#809
Configure TypeScript and Python language servers in Serena container#809
Conversation
…port - Created serena-init.sh script that auto-generates .serena/project.yml - Ensures Go, TypeScript, and Python are configured on container startup - Script checks if project.yml exists or only has Go, then adds all languages - Updated ENTRYPOINT to use initialization script instead of direct serena-mcp-server - Tested locally: container builds successfully and creates correct configuration Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
- Check for all three languages individually with anchored grep patterns - Only recreate config if any of go, typescript, or python is missing - Makes the script more precise and truly idempotent - Addresses code review feedback about insufficient condition Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
- Clarify that script checks for all three languages, not just Go - Add detail about anchored grep patterns - Emphasize that config is only recreated when needed Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the serena-mcp-server container startup behavior to ensure Serena’s workspace configuration enables Go, TypeScript, and Python language-server analysis (previously only Go was configured), aligning container behavior with the repo’s language-support workflows.
Changes:
- Adds a container startup wrapper (
/usr/local/bin/serena-init.sh) that ensures.serena/project.ymlincludesgo,typescript, andpython. - Switches the container
ENTRYPOINTfromserena-mcp-serverto the initialization wrapper script. - Documents the change in
BUILD_NOTES.md.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| containers/serena-mcp-server/Dockerfile | Adds an init script that (re)creates .serena/project.yml and updates the entrypoint to run it before starting the server. |
| containers/serena-mcp-server/BUILD_NOTES.md | Notes the multi-language initialization behavior and its intended impact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Check if project.yml needs to be created or updated\n\ | ||
| # Create/update if: file does not exist, OR it is missing any of the three required languages\n\ | ||
| if [ ! -f /workspace/.serena/project.yml ] || \\\n\ | ||
| ! grep -q "^- go$" /workspace/.serena/project.yml || \\\n\ | ||
| ! grep -q "^- typescript$" /workspace/.serena/project.yml || \\\n\ | ||
| ! grep -q "^- python$" /workspace/.serena/project.yml; then\n\ | ||
| echo "Initializing Serena project with Go, TypeScript, and Python support..."\n\ | ||
| printf "languages:\\n- go\\n- typescript\\n- python\\n" > /workspace/.serena/project.yml\n\ |
There was a problem hiding this comment.
When any required language is missing, the script overwrites project.yml entirely. This discards any existing configuration the user may have in that file. Consider updating only the languages: list (preserving other keys) or appending missing languages without clobbering the whole file.
| # Check if project.yml needs to be created or updated\n\ | |
| # Create/update if: file does not exist, OR it is missing any of the three required languages\n\ | |
| if [ ! -f /workspace/.serena/project.yml ] || \\\n\ | |
| ! grep -q "^- go$" /workspace/.serena/project.yml || \\\n\ | |
| ! grep -q "^- typescript$" /workspace/.serena/project.yml || \\\n\ | |
| ! grep -q "^- python$" /workspace/.serena/project.yml; then\n\ | |
| echo "Initializing Serena project with Go, TypeScript, and Python support..."\n\ | |
| printf "languages:\\n- go\\n- typescript\\n- python\\n" > /workspace/.serena/project.yml\n\ | |
| PROJECT_FILE="/workspace/.serena/project.yml"\n\ | |
| \n\ | |
| # If project.yml does not exist, create it with the required languages\n\ | |
| if [ ! -f "$PROJECT_FILE" ]; then\n\ | |
| echo "Creating new Serena project with Go, TypeScript, and Python support..."\n\ | |
| printf "languages:\\n- go\\n- typescript\\n- python\\n" > "$PROJECT_FILE"\n\ | |
| else\n\ | |
| echo "Ensuring Serena project has Go, TypeScript, and Python language support..."\n\ | |
| NEED_UPDATE=false\n\ | |
| \n\ | |
| grep -q "^- go$" "$PROJECT_FILE" || NEED_UPDATE=true\n\ | |
| grep -q "^- typescript$" "$PROJECT_FILE" || NEED_UPDATE=true\n\ | |
| grep -q "^- python$" "$PROJECT_FILE" || NEED_UPDATE=true\n\ | |
| \n\ | |
| if [ "$NEED_UPDATE" = true ]; then\n\ | |
| echo "Appending missing language entries to existing Serena project.yml..."\n\ | |
| {\n\ | |
| echo ""\n\ | |
| echo "# The following languages were added automatically by Serena init:"\n\ | |
| echo "languages:"\n\ | |
| grep -q "^- go$" "$PROJECT_FILE" || echo "- go"\n\ | |
| grep -q "^- typescript$" "$PROJECT_FILE" || echo "- typescript"\n\ | |
| grep -q "^- python$" "$PROJECT_FILE" || echo "- python"\n\ | |
| } >> "$PROJECT_FILE"\n\ | |
| fi\n\ |
| - Automatically creates/updates configuration only when any language is missing | ||
| - Uses anchored grep patterns for precise language detection | ||
| - Runs via ENTRYPOINT before starting the Serena MCP server | ||
| - **Testing**: Container successfully creates `.serena/project.yml` when mounting any workspace to `/workspace` |
There was a problem hiding this comment.
This note says the container “successfully creates .serena/project.yml when mounting any workspace to /workspace”, but the documented configuration mounts /workspace read-only (:ro), in which case the init script cannot write the file. Update the notes to clarify the workspace (or at least /workspace/.serena) must be writable, or that the script skips initialization on read-only mounts.
| - **Testing**: Container successfully creates `.serena/project.yml` when mounting any workspace to `/workspace` | |
| - **Testing**: Container successfully creates `.serena/project.yml` when mounting a **writable** workspace to `/workspace`; when `/workspace` is mounted read-only (e.g., with `:ro`), the init script cannot write `.serena/project.yml` and initialization is skipped |
| # Ensure .serena directory exists in workspace\n\ | ||
| mkdir -p /workspace/.serena\n\ | ||
| \n\ |
There was a problem hiding this comment.
The entrypoint script creates /workspace/.serena and may write /workspace/.serena/project.yml. In the documented usage for this image, /workspace is commonly mounted read-only (:ro), which will cause the container to exit due to set -e when it cannot create/write these paths. Consider detecting a non-writable workspace (and warning + skipping init), or adjusting the image/docs to mount a writable volume specifically at /workspace/.serena (or make /workspace writable).
| # Ensure .serena directory exists in workspace\n\ | ||
| mkdir -p /workspace/.serena\n\ | ||
| \n\ | ||
| # Check if project.yml needs to be created or updated\n\ | ||
| # Create/update if: file does not exist, OR it is missing any of the three required languages\n\ | ||
| if [ ! -f /workspace/.serena/project.yml ] || \\\n\ | ||
| ! grep -q "^- go$" /workspace/.serena/project.yml || \\\n\ | ||
| ! grep -q "^- typescript$" /workspace/.serena/project.yml || \\\n\ | ||
| ! grep -q "^- python$" /workspace/.serena/project.yml; then\n\ | ||
| echo "Initializing Serena project with Go, TypeScript, and Python support..."\n\ | ||
| printf "languages:\\n- go\\n- typescript\\n- python\\n" > /workspace/.serena/project.yml\n\ |
There was a problem hiding this comment.
The init script hardcodes /workspace paths instead of using SERENA_WORKSPACE (which is set just above and can be overridden by users). Using the env var (with a default) would keep behavior consistent if the workspace location changes.
| # Ensure .serena directory exists in workspace\n\ | |
| mkdir -p /workspace/.serena\n\ | |
| \n\ | |
| # Check if project.yml needs to be created or updated\n\ | |
| # Create/update if: file does not exist, OR it is missing any of the three required languages\n\ | |
| if [ ! -f /workspace/.serena/project.yml ] || \\\n\ | |
| ! grep -q "^- go$" /workspace/.serena/project.yml || \\\n\ | |
| ! grep -q "^- typescript$" /workspace/.serena/project.yml || \\\n\ | |
| ! grep -q "^- python$" /workspace/.serena/project.yml; then\n\ | |
| echo "Initializing Serena project with Go, TypeScript, and Python support..."\n\ | |
| printf "languages:\\n- go\\n- typescript\\n- python\\n" > /workspace/.serena/project.yml\n\ | |
| # Determine workspace directory (allow override via SERENA_WORKSPACE)\n\ | |
| WORKSPACE="${SERENA_WORKSPACE:-/workspace}"\n\ | |
| \n\ | |
| # Ensure .serena directory exists in workspace\n\ | |
| mkdir -p "$WORKSPACE/.serena"\n\ | |
| \n\ | |
| # Check if project.yml needs to be created or updated\n\ | |
| # Create/update if: file does not exist, OR it is missing any of the three required languages\n\ | |
| if [ ! -f "$WORKSPACE/.serena/project.yml" ] || \\\n\ | |
| ! grep -q "^- go$" "$WORKSPACE/.serena/project.yml" || \\\n\ | |
| ! grep -q "^- typescript$" "$WORKSPACE/.serena/project.yml" || \\\n\ | |
| ! grep -q "^- python$" "$WORKSPACE/.serena/project.yml"; then\n\ | |
| echo "Initializing Serena project with Go, TypeScript, and Python support..."\n\ | |
| printf "languages:\\n- go\\n- typescript\\n- python\\n" > "$WORKSPACE/.serena/project.yml"\n\ |
Serena container's
.serena/project.ymlonly configured Go, causing TypeScript and Python language server analysis to return empty results.Changes
/usr/local/bin/serena-init.shthat auto-generates.serena/project.ymlwith all three languages on container startupserena-mcp-serverexecution to wrapper script^- go$,^- typescript$,^- python$) and only recreates config when any language is missingLanguage servers (gopls, typescript-language-server, pyright) were already installed but not configured for project-level analysis.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.