Developers

Customize eME Server with OpenCode

eME Server is 100% open source. This tutorial takes you from a fresh machine to an AI coding agent that adds skills, pages and data to your own eME server, using the workflow defined in the eme-server repository on GitHub.

How the pieces fit

There are four parts. Knowing which part owns what makes it easy to tell an AI agent where a change belongs.

  • eme-server is the Java server you run. Your copy is a Git fork, so your changes stay yours.
  • Plugins hold the code. Java lives in plugins/*/code, Spring beans are registered in plugins/*/html/src/plugin.xml, and pages are configured by .xconf files.
  • OpenCode is the AI coding agent. It reads AGENTS.md and the skills in .agents/skills for the project rules.
  • MediaDB MCP is the server's own Model Context Protocol endpoint. OpenCode connects to it so the agent can work with live data while it codes.

EME World is the parent server

EME World sits in the middle. It holds the People and the Teams: one free login and one eME Profile per person, and the group chats and shared goals of each team. Every eME Server you build connects to it, so people sign in once and take their identity and teams with them.

Each eME Server is a child of EME World and owns its own content. See the eME Pro page for the full network diagram.

  • Server Chat Welcome is the node that connects the server to EME World, ahead of the server itself.
  • Collections and Tutorials belong to that server and are organized by topic.
  • Data Tools are the tools a server uses to work with its own data.
EME World is the parent server and holds People and Groups. Each connected eME Server, such as UN News, Cumbre de Cocreación or your own, has a Server Chat Welcome node, a Data Tools, and its own Collections and Tutorials organized by topic.

1. Prerequisites

  • A Linux machine (the scripts are bash) with git and curl.
  • A Java JDK. The server uses JAVA_HOME, then SDKMAN, then /usr/lib/jvm/default-java.
  • VS Code. The developer setup opens a workspace.code-workspace and the server runs as a VS Code debug session.
  • The OpenCode CLI, installed so that opencode is on your path.
  • A model that speaks the OpenAI compatible API, hosted by you or a provider.
  • A GitHub account, so you can fork the repository.

Run everything as your normal user. bin/eme.sh refuses to run as root, except for dockerstart.

2. Set up your server

Create the developer environment

This is the AI developer setup from the repository README. It clones eme-server into the folder you name.

# see all commands
curl -fsSL get-eme.eme.world | bash -s -- help

# clone eme-server and prepare it for development
curl -L get-eme.eme.world | bash -s -- developer $HOME/git/MyEmEServer

The developer command creates the folder if needed, writes a .env with INSTANCE, SITE and NODENUMBER, clones eme-server, updates the plugins, copies the default site into webapp/site, and opens the VS Code workspace.

Fork it so your changes are saved

The clone points at the shared repository. To keep your own work, fork eme-server on GitHub and use your fork for a custom client:

git clone https://github.com/YOUR-ORG/eme-server-myserver.git
cd eme-server-myserver
bin/pluginspull.sh

Start the server

Start it from VS Code with bin/start.sh, which also installs the Remote Control extension if it is missing. Use bin/restart.sh after changes. Do not start Tomcat yourself with eme.sh start.

3. Sign in for API access

Users have no password. Scripts, the MCP endpoint and agents all authenticate with a Bearer token from bin/refreshtoken.sh. Register once, from a terminal:

# emails you a login code and registers a key
bin/refreshtoken.sh --register

# or use an application password
bin/refreshtoken.sh --app-password

After that, the script reads EME_USER, EME_KEY_ID and EME_PRIVATE_KEY (or EME_APP_PASSWORD) from the .env in your project root, caches a 7 day token, and prints the token as its last line:

AUTH="Authorization: Bearer $(bin/refreshtoken.sh | tail -n1)"
curl -H "$AUTH" http://localhost:8080/site/mediadb/ai/mcp/

Never paste a token into a document or script. Use bin/refreshtoken.sh --force to log in again after a 401.

4. Connect OpenCode

The project root contains an opencodeglobal.json. It defines the model provider and the server's MCP endpoint. A minimal version looks like this:

{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "my-llm": {
      "package": "aisdk:@ai-sdk/openai-compatible",
      "settings": { "baseURL": "https://your-llm-host/v1" },
      "models": {
        "my-model": {
          "name": "my-model",
          "capabilities": { "tools": true, "input": ["text"], "output": ["text"] },
          "limit": { "context": 80000, "output": 16384 }
        }
      }
    }
  },
  "model": { "providerID": "my-llm", "model": "my-model" },
  "mcp": {
    "eme-mediadb": {
      "type": "remote",
      "url": "http://localhost:8080/site/mediadb/ai/mcp/",
      "headers": { "Authorization": "Bearer {env:EME_TOKEN}" },
      "enabled": true
    }
  }
}

OpenCode only reads EME_TOKEN at startup, so start it with the wrapper script. It fetches a fresh token and then runs opencode from the project root:

bin/opencode.sh

Prefer a browser?

Run the OpenCode web interface as a background service:

bin/opencoded.sh start     # also: restart, stop, status

The host and port come from the server block of opencodeglobal.json. Sign in with the one time pairing link the script prints. A link works once and expires in 5 minutes, so run the script again for a new one. Behind a proxy, set OPENCODE_PAIR_URL to the public address.

5. Rules the agent follows

The repository's AGENTS.md is loaded by OpenCode, so the agent works the same way you would. The rules that matter most when customizing:

TopicRule
Server logicWrite Java in plugins/*/code, register a bean in plugin.xml, and call it from the page's .xconf with <path-action name="ModuleName.method"/>. No Groovy scripts.
After Java, plugin.xml or jar changesRun bin/restart.sh, then wait for http://localhost:8080/site/ to respond before testing.
After .xconf changesClear the page manager cache. No restart is needed.
After data list XML changesReset the table from XML, then clear the caches.
The description fieldIt is search text for the index, not a real description. Use longdescription.

6. Agent skills

Skills are short guides in .agents/skills that teach the agent how this project does things. They keep it from guessing at bean ids, data ids and reload steps. A few you will use often:

  • create-java-ai-skill: add a Java automation step to the AI pipeline.
  • mediadb-auth: how people, apps, scripts and agents log in.
  • reload-list-data: reset data list tables after you edit their XML.
  • opencode-running: how a chat message becomes an OpenCode session.
  • opencode-v2-api: the OpenCode HTTP API and event stream.

Browse the folder for more. Add your own the same way: one folder with a SKILL.md that says when to use it.

7. Example: add an AI skill

Start bin/opencode.sh and describe the result you want. Naming the skill points the agent at the right conventions:

Use the create-java-ai-skill skill to add a new AI skill called
WelcomeNoteSkill. It should run in the agentorchestrator scenario and
post a short welcome message to the chat.

The agent will do the following. Review each step in your diff:

  1. Write the class under plugins/finder/code/org/entermediadb/ai/skills/, extending BaseSkill and overriding process(AgentContext).
  2. Register the Spring bean in plugins/finder/html/src/plugin.xml.
  3. Add the row to plugins/catalog/html/data/lists/aiskill*/*.xml, and append the step to automationstep/<scenario>.xml.

The bean id, the data row id and the step's aiskill value must be the same string (the class name with a lowercase first letter, here welcomeNoteSkill). A mismatch is the most common reason a new skill does not run.

The contract every skill implements:

public interface Skill
{
    void processStarting(AgentContext inContext);
    void process(AgentContext inContext);
    void processUpdate(AgentContext inContext);    // broadcast the last response, keep working
    void processCompleted(AgentContext inContext); // broadcast the last response, then run its exec step
}

8. The edit and reload loop

Each kind of change has its own reload step. Ask the agent to run them, or run them yourself:

# Java, plugin.xml or jars under plugins/*/lib
bin/restart.sh

# .xconf page configuration
curl -H "$AUTH" http://localhost:8080/openedit/views/filemanager/clearpagemanager.html

# data list XML, one call per table, then clear caches
for t in automationscenario automationstep; do
  curl -H "$AUTH" "http://localhost:8080/site/find/views/settings/lists/datamanager/list/restoredata.html?searchtype=$t&oemaxlevel=1"
done
curl -H "$AUTH" http://localhost:8080/site/find/views/settings/status/tools/clearcaches.html

A data reset overwrites records with what is in the XML, so edits made only in the UI are lost. It does not delete records you removed or renamed in the XML, so delete those first with DELETE /site/mediadb/services/lists/data/<searchtype>/<id>.

9. OpenCode from inside a chat

OpenCode can also run as a step in an agent job, so people can ask for a customization from the chat screen. The eme_server_custom_skills scenario chains the skills: one turns the chat message into a request, one starts or resumes the OpenCode session, one polls progress and shows a status card, and two send a person's answer or approval back to OpenCode. Questions and security prompts from the agent appear in the chat as forms the person can answer.

The code is in plugins/finder/code/org/entermediadb/ai/skills/OpenCode*Skill.java. Read the opencode-running skill before changing it.

10. Save, update and deploy

# commit everything, pull, and push to main (the argument is the commit message)
bin/eme.sh branchpush /full/path/eme-server-myserver "Add welcome note skill"

# pull the latest eme-server into your server, then restart
bin/eme.sh update /full/path/eme-server-myserver
bin/restart.sh

# if you forked, merge the shared project's latest changes
bin/eme.sh updatefork /full/path/eme-server-myserver

To run your server in Docker, clone your fork, run bin/pluginspull.sh, then create the instance. The arguments are the server path, a node number, and the user that will own it:

bin/eme.sh dockercreate /full/path/eme-server-myserver 20 entermedia