Add MCP server
This commit is contained in:
@@ -1,28 +1,29 @@
|
||||
package geo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/paulmach/orb/geojson"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type GeoService struct {
|
||||
peliasURL string
|
||||
geoType string
|
||||
baseURL string
|
||||
autocompleteURL string
|
||||
}
|
||||
|
||||
func NewGeoService(peliasURL string) *GeoService {
|
||||
return &GeoService{peliasURL: peliasURL}
|
||||
func NewGeoService(geoType, baseURL, autocompleteEndpoint string) *GeoService {
|
||||
return &GeoService{
|
||||
geoType: geoType,
|
||||
baseURL: baseURL,
|
||||
autocompleteURL: baseURL + autocompleteEndpoint,
|
||||
}
|
||||
}
|
||||
|
||||
type AutocompleteResult struct {
|
||||
Features []any
|
||||
}
|
||||
|
||||
func (s *GeoService) Autocomplete(text string) (*AutocompleteResult, error) {
|
||||
resp, err := http.Get(fmt.Sprintf("%s/autocomplete?text=%s", s.peliasURL, text))
|
||||
func (s *GeoService) Autocomplete(text string) (*geojson.FeatureCollection, error) {
|
||||
resp, err := http.Get(s.autocompleteURL + text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -34,17 +35,11 @@ func (s *GeoService) Autocomplete(text string) (*AutocompleteResult, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var response map[string]any
|
||||
if err := json.Unmarshal(body, &response); err != nil {
|
||||
featureCollection, err := geojson.UnmarshalFeatureCollection(body)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to unmarshal feature collection")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
features, ok := response["features"].([]any)
|
||||
if !ok {
|
||||
features = []any{}
|
||||
}
|
||||
|
||||
return &AutocompleteResult{
|
||||
Features: features,
|
||||
}, nil
|
||||
return featureCollection, nil
|
||||
}
|
||||
Reference in New Issue
Block a user