|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script creates an MCP SDK repo from x/tools/internal/mcp (and friends). |
| 4 | +# It will be used as a one-off to create github.com/modelcontextprotocol/go-sdk. |
| 5 | +# |
| 6 | +# Requires https://github.com/newren/git-filter-repo. |
| 7 | + |
| 8 | +set -eu |
| 9 | + |
| 10 | +# Check if exactly one argument is provided |
| 11 | +if [ "$#" -ne 1 ]; then |
| 12 | + echo "create-repo.sh: create a standalone mcp SDK repo from x/tools" |
| 13 | + echo "Usage: $0 <mcp repo destination>" |
| 14 | + exit 1 |
| 15 | +fi >&2 |
| 16 | + |
| 17 | +src=$(go list -m -f {{.Dir}} golang.org/x/tools) |
| 18 | +dest="$1" |
| 19 | + |
| 20 | +echo "Filtering MCP commits from ${src} to ${dest}..." >&2 |
| 21 | + |
| 22 | +startdir=$(pwd) |
| 23 | +tempdir=$(mktemp -d) |
| 24 | +function cleanup { |
| 25 | + echo "cleaning up ${tempdir}" |
| 26 | + rm -rf "$tempdir" |
| 27 | +} >&2 |
| 28 | +trap cleanup EXIT SIGINT |
| 29 | + |
| 30 | +echo "Checking out to ${tempdir}" |
| 31 | + |
| 32 | +git clone --bare "${src}" "${tempdir}" |
| 33 | +git -C "${tempdir}" --git-dir=. filter-repo \ |
| 34 | + --path internal/mcp/jsonschema --path-rename internal/mcp/jsonschema:jsonschema \ |
| 35 | + --path internal/mcp/design --path-rename internal/mcp/design:design \ |
| 36 | + --path internal/mcp/examples --path-rename internal/mcp/examples:examples \ |
| 37 | + --path internal/mcp/internal --path-rename internal/mcp/internal:internal \ |
| 38 | + --path internal/mcp/README.md --path-rename internal/mcp/README.md:README.md \ |
| 39 | + --path internal/mcp/CONTRIBUTING.md --path-rename internal/mcp/CONTRIBUTING.md:CONTRIBUTING.md \ |
| 40 | + --path internal/mcp --path-rename internal/mcp:mcp \ |
| 41 | + --path internal/jsonrpc2_v2 --path-rename internal/jsonrpc2_v2:internal/jsonrpc2 \ |
| 42 | + --path internal/xcontext \ |
| 43 | + --replace-text "${startdir}/mcp-repo-replace.txt" \ |
| 44 | + --force |
| 45 | +mkdir ${dest} |
| 46 | +cd "${dest}" |
| 47 | +git init |
| 48 | + |
| 49 | +cat << EOF > LICENSE |
| 50 | +MIT License |
| 51 | +
|
| 52 | +Copyright (c) 2025 Go MCP SDK Authors |
| 53 | +
|
| 54 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 55 | +of this software and associated documentation files (the "Software"), to deal |
| 56 | +in the Software without restriction, including without limitation the rights |
| 57 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 58 | +copies of the Software, and to permit persons to whom the Software is |
| 59 | +furnished to do so, subject to the following conditions: |
| 60 | +
|
| 61 | +The above copyright notice and this permission notice shall be included in all |
| 62 | +copies or substantial portions of the Software. |
| 63 | +
|
| 64 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 65 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 66 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 67 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 68 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 69 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 70 | +SOFTWARE. |
| 71 | +EOF |
| 72 | + |
| 73 | +git add LICENSE && git commit -m "Initial commit: add LICENSE" |
| 74 | +git remote add filtered_source "${tempdir}" |
| 75 | +git pull filtered_source master --allow-unrelated-histories |
| 76 | +git remote remove filtered_source |
| 77 | +go mod init github.com/modelcontextprotocol/go-sdk && go get [email protected] |
| 78 | +go mod tidy |
| 79 | +git add go.mod go.sum |
| 80 | +git commit -m "all: add go.mod and go.sum file" |
0 commit comments