Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target
/result
externals/
rules.sled/
*.sled/
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,42 @@ make

The binary is at `target/release/zhtw-mcp`.

### Nix

With Nix flakes enabled, run the package directly:

```bash
nix run github:sysprog21/zhtw-mcp -- lint README.md
```

To register the MCP server without installing the binary globally:

```bash
claude mcp add zhtw-mcp -- nix run github:sysprog21/zhtw-mcp --
```

Codex CLI or other MCP clients can use `nix run` as the server command:

```json
{
"mcpServers": {
"zhtw-mcp": {
"command": "nix",
"args": ["run", "github:sysprog21/zhtw-mcp", "--"]
}
}
}
```

If you prefer a persistent command on `PATH`, install the flake package:

```bash
nix profile install github:sysprog21/zhtw-mcp
claude mcp add zhtw-mcp -- zhtw-mcp
```

From a local checkout, replace `github:sysprog21/zhtw-mcp` with `.`.

### Installing

The quickest way to build, install to `~/.local/bin`, and register with Claude Code:
Expand Down
63 changes: 63 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

155 changes: 155 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
description = "MCP server for Traditional Chinese (zh-TW) text linting and normalization";

inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1"; # unstable Nixpkgs
fenix = {
url = "https://flakehub.com/f/nix-community/fenix/0.1";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
{ self, ... }@inputs:

let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forEachSupportedSystem =
f:
inputs.nixpkgs.lib.genAttrs supportedSystems (
system:
f {
inherit system;
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
self.overlays.default
];
};
}
);
in
{
overlays.default = final: prev: {
rustToolchain =
with inputs.fenix.packages.${final.stdenv.hostPlatform.system};
combine (
with stable;
[
clippy
rustc
cargo
rustfmt
rust-src
]
);

zhtw-mcp =
let
openccRev = "0ad13e022313ab62daf9b7ef79047b2d084a8868";
openccDictUrl =
file: "https://raw.githubusercontent.com/BYVoid/OpenCC/${openccRev}/data/dictionary/${file}";
openccDicts = final.linkFarm "opencc-dictionaries" [
{
name = "STPhrases.txt";
path = final.fetchurl {
url = openccDictUrl "STPhrases.txt";
hash = "sha256-nC1CoWSP9+x+d003fHpz9yECr6TmGMLZ3dlfkvq2lgA=";
};
}
{
name = "STCharacters.txt";
path = final.fetchurl {
url = openccDictUrl "STCharacters.txt";
hash = "sha256-nO37i/E6IgCHED2altn1YFDDQcJKgJy85chckEVFZVc=";
};
}
{
name = "TWVariants.txt";
path = final.fetchurl {
url = openccDictUrl "TWVariants.txt";
hash = "sha256-iUc+luP2HpvT8uMDudiKycqmHv+x+q3O+U/15luO1Us=";
};
}
];
rustPlatform = final.makeRustPlatform {
cargo = final.rustToolchain;
rustc = final.rustToolchain;
};
in
rustPlatform.buildRustPackage (finalAttrs: {
pname = "zhtw-mcp";
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version;
Comment thread
pan93412 marked this conversation as resolved.

src = final.lib.cleanSource ./.;

cargoHash = "sha256-vwguHA1z9ne6P8Q+JBMafAIkhihMgBOdxbHF0HrWLes=";

nativeBuildInputs = [
final.python3
final.rustToolchain
];

preBuild = ''
mkdir -p data/opencc
cp ${openccDicts}/STPhrases.txt data/opencc/STPhrases.txt
cp ${openccDicts}/STCharacters.txt data/opencc/STCharacters.txt
cp ${openccDicts}/TWVariants.txt data/opencc/TWVariants.txt
python3 scripts/gen-s2t-tables.py
rustfmt src/engine/s2t_data.rs
Comment thread
pan93412 marked this conversation as resolved.
'';

cargoTestFlags = [
"--lib"
"--bins"
];

meta = with final.lib; {
description = "MCP server for Traditional Chinese (zh-TW) text linting and normalization";
homepage = "https://github.com/sysprog21/zhtw-mcp";
license = licenses.mit;
mainProgram = "zhtw-mcp";
platforms = platforms.unix;
};
});
};

packages = forEachSupportedSystem (
{ pkgs, ... }:
{
inherit (pkgs) zhtw-mcp;
default = pkgs.zhtw-mcp;
}
);

devShells = forEachSupportedSystem (
{ pkgs, system }:
{
default = pkgs.mkShell {
packages = with pkgs; [
rustToolchain
openssl
pkg-config
cargo-deny
cargo-edit
cargo-watch
rust-analyzer
self.formatter.${system}
];

env = {
# Required by rust-analyzer
RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library";
};
};
}
);

formatter = forEachSupportedSystem ({ pkgs, ... }: pkgs.nixfmt);
};
}
Loading