File simple-mcp.spec of Package simple-mcp

#
# spec file for package simple-mcp
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

Name:           simple-mcp
Version:        0.9.1
Release:        1.vojtech
Summary:        Simple MCP server in Go
License:        MIT
URL:            https://github.com/vojtechpavlik/simple-mcp

# Source0 (Application) and Source1 (Vendor) are generated by the _service file
Source0:        %{name}-%{version}.tar.gz
Source1:        vendor.tar.gz

BuildRequires:  go >= 1.23
BuildRequires:  golang-packaging
BuildRequires:  xz
BuildRequires:  systemd-rpm-macros
BuildRequires:  mandoc-bin
BuildRequires:  fdupes
# It's be nice to also have markdownlint-cli2, but not available on openSUSE
# so markdown linting will be skipped

%{?systemd_requires}

%description
This is a simple MCP (Model Context Protocol) written in Go, with 
a shell interface, where an user can expose shell commands through MCP Tools.

%package unified-core
Summary:        Unified Core configuration for simple-mcp
Requires:       %{name} = %{version}
BuildArch:      noarch
# This ensures the service restarts if we switch configs
%{?systemd_requires}

%description unified-core
This package provides the Unified Core configuration for simple-mcp.
It installs the necessary schemas and example files and configures
the systemd service to use the unified-core.yaml configuration
instead of the default.

%prep
# Unpack Source0 (app) and Source1 (vendor)
%autosetup -p1 -a 1

%build
# Build the server binary
CGO_ENABLED=1 go build \
   -mod=vendor \
   -buildmode=pie \
   -ldflags="-w -s" \
   -o %{name}

# Build the client binary
CGO_ENABLED=1 go build \
   -mod=vendor \
   -buildmode=pie \
   -ldflags="-w -s" \
   -o %{name}-cli cli/main.go

%install
# 1. Install the binaries
install -D -m 0755 %{name} %{buildroot}%{_bindir}/%{name}
install -D -m 0755 %{name}-cli %{buildroot}%{_bindir}/%{name}-cli

# 2. Install the configuration file from the source tarball
install -D -m 0644 simple-mcp.yaml %{buildroot}%{_sysconfdir}/simple-mcp/simple-mcp.yaml

# 3. Install the systemd service file from the source tarball
# (Assumes simple-mcp.service is now at the root of the git repo)
install -D -m 0644 simple-mcp.service %{buildroot}%{_unitdir}/%{name}.service

# 4. Install the manual page 
install -D -m 0644 simple-mcp.1 %{buildroot}%{_mandir}/man1/simple-mcp.1
install -D -m 0644 simple-mcp-cli.1 %{buildroot}%{_mandir}/man1/simple-mcp-cli.1

# --- unified-core config installation ---

# 1. Install the main unified configuration file
install -D -m 0644 unified-core.yaml %{buildroot}%{_sysconfdir}/simple-mcp/unified-core.yaml

# 2. Install the referenced schema file
install -D -m 0644 elemental-schema.json %{buildroot}%{_sysconfdir}/simple-mcp/elemental-schema.json

# 3. Install the example directory (recursively)
# We create the directory first, then copy contents
install -d -m 0755 %{buildroot}%{_sysconfdir}/simple-mcp/elemental-example
cp -r elemental-example/* %{buildroot}%{_sysconfdir}/simple-mcp/elemental-example/
# Fix permissions for the copied files to ensure they are not executable
find %{buildroot}%{_sysconfdir}/simple-mcp/elemental-example -type f -exec chmod 0644 {} +

# 4. Create a Systemd Drop-in to switch the config
# This overrides the ExecStart command to point to unified-core.yaml
install -d -m 0755 %{buildroot}%{_unitdir}/%{name}.service.d
cat > %{buildroot}%{_unitdir}/%{name}.service.d/unified-core.conf <<EOF
[Service]
ExecStart=
ExecStart=%{_bindir}/%{name} --config %{_sysconfdir}/simple-mcp/unified-core.yaml --listen-addr localhost:8080
EOF

%fdupes -s %{buildroot}

%check
# Run the test suite
# -v for verbose output in the build logs
go test -v ./...

%pre
%service_add_pre %{name}.service

%post
%service_add_post %{name}.service

%preun
%service_del_preun %{name}.service

%postun
%service_del_postun %{name}.service

%files
%license LICENSE
# %%doc copies these from the source dir to /usr/share/doc/packages/simple-mcp/
%doc README.md mcphost.yaml systemprompt.txt
%{_bindir}/%{name}
%{_bindir}/%{name}-cli
%{_unitdir}/%{name}.service
%{_mandir}/man1/simple-mcp.1*
%{_mandir}/man1/simple-mcp-cli.1*

# Mark the config file so it isn't overwritten on updates
%dir %{_sysconfdir}/simple-mcp
%config(noreplace) %{_sysconfdir}/simple-mcp/simple-mcp.yaml


%files unified-core
%config(noreplace) %{_sysconfdir}/simple-mcp/unified-core.yaml
%config %{_sysconfdir}/simple-mcp/elemental-schema.json
%config %{_sysconfdir}/simple-mcp/elemental-example/
%dir %{_unitdir}/%{name}.service.d
%{_unitdir}/%{name}.service.d/unified-core.conf

%changelog
openSUSE Build Service is sponsored by